]> git.proxmox.com Git - mirror_qemu.git/commitdiff
slirp/misc: Use the GLib memory allocation APIs
authorzhanghailiang <zhang.zhanghailiang@huawei.com>
Tue, 19 Aug 2014 08:30:17 +0000 (16:30 +0800)
committerMichael Tokarev <mjt@tls.msk.ru>
Sun, 24 Aug 2014 09:16:32 +0000 (13:16 +0400)
Here we don't check the return value of malloc() which may fail.
Use the g_new() instead, which will abort the program when
there is not enough memory.

Also, use g_strdup instead of strdup and remove the unnecessary
strdup function.

Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Benoît Canet <benoit.canet@nodalink.com>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
slirp/misc.c
slirp/misc.h
slirp/slirp_config.h

index b8eb74cab03d86ded061e42daee30cf0405c9cf7..6543dc777298463931ae82fbb94619c8b0ee5902 100644 (file)
@@ -54,11 +54,11 @@ int add_exec(struct ex_list **ex_ptr, int do_pty, char *exec,
        }
 
        tmp_ptr = *ex_ptr;
-       *ex_ptr = (struct ex_list *)malloc(sizeof(struct ex_list));
+       *ex_ptr = g_new(struct ex_list, 1);
        (*ex_ptr)->ex_fport = port;
        (*ex_ptr)->ex_addr = addr;
        (*ex_ptr)->ex_pty = do_pty;
-       (*ex_ptr)->ex_exec = (do_pty == 3) ? exec : strdup(exec);
+       (*ex_ptr)->ex_exec = (do_pty == 3) ? exec : g_strdup(exec);
        (*ex_ptr)->ex_next = tmp_ptr;
        return 0;
 }
@@ -187,7 +187,7 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
                           bptr++;
                        c = *bptr;
                        *bptr++ = (char)0;
-                       argv[i++] = strdup(curarg);
+                       argv[i++] = g_strdup(curarg);
                   } while (c);
 
                 argv[i] = NULL;
@@ -228,20 +228,6 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
 }
 #endif
 
-#ifndef HAVE_STRDUP
-char *
-strdup(str)
-       const char *str;
-{
-       char *bptr;
-
-       bptr = (char *)malloc(strlen(str)+1);
-       strcpy(bptr, str);
-
-       return bptr;
-}
-#endif
-
 void slirp_connection_info(Slirp *slirp, Monitor *mon)
 {
     const char * const tcpstates[] = {
index ba8beb1b17e3d708119cd135421cbe1bcd423042..41a32583daad25ca0df4125dab87748df9873c4b 100644 (file)
@@ -16,10 +16,6 @@ struct ex_list {
        struct ex_list *ex_next;
 };
 
-#ifndef HAVE_STRDUP
-char *strdup(const char *);
-#endif
-
 #define EMU_NONE 0x0
 
 /* TCP emulations */
index 18db45c8e42eb57d84bf47991890c36fc913975e..896d8022eb677b089a8df53c463f7e48ea4049c7 100644 (file)
@@ -72,9 +72,6 @@
 /* Define if you have strerror */
 #define HAVE_STRERROR
 
-/* Define if you have strdup() */
-#define HAVE_STRDUP
-
 /* Define according to how time.h should be included */
 #define TIME_WITH_SYS_TIME 0
 #undef HAVE_SYS_TIME_H