From 2439a79b0dfcad1e066d2d1cd21873dc8b24696b Mon Sep 17 00:00:00 2001 From: zhanghailiang Date: Tue, 19 Aug 2014 16:30:17 +0800 Subject: slirp/misc: Use the GLib memory allocation APIs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Alex Bennée Reviewed-by: Benoît Canet Signed-off-by: Michael Tokarev --- misc.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'misc.c') diff --git a/misc.c b/misc.c index 5762c20..2f0f7ca 100644 --- a/misc.c +++ b/misc.c @@ -51,11 +51,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; } @@ -180,7 +180,7 @@ int 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; @@ -223,18 +223,6 @@ int 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[] = { -- cgit v1.1