Received: from eggs.gnu.org ([2001:4830:134:3::10]:48835) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XLXy3-0003dr-JF for qemu-devel@nongnu.org; Sun, 24 Aug 2014 09:36:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XLXxy-0006ku-PJ for qemu-devel@nongnu.org; Sun, 24 Aug 2014 09:36:23 -0400 From: Michael Tokarev Date: Sun, 24 Aug 2014 17:30:58 +0400 Message-Id: <1408887062-30022-8-git-send-email-mjt@msgid.tls.msk.ru> In-Reply-To: <1408887062-30022-1-git-send-email-mjt@msgid.tls.msk.ru> References: <1408887062-30022-1-git-send-email-mjt@msgid.tls.msk.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 07/11] slirp/misc: Use the GLib memory allocation APIs List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-trivial@nongnu.org, Michael Tokarev , zhanghailiang From: zhanghailiang 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=C3=A9e Reviewed-by: Beno=C3=AEt Canet Signed-off-by: Michael Tokarev --- slirp/misc.c | 20 +++----------------- slirp/misc.h | 4 ---- slirp/slirp_config.h | 3 --- 3 files changed, 3 insertions(+), 24 deletions(-) diff --git a/slirp/misc.c b/slirp/misc.c index b8eb74c..6543dc7 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -54,11 +54,11 @@ int add_exec(struct ex_list **ex_ptr, int do_pty, cha= r *exec, } =20 tmp_ptr =3D *ex_ptr; - *ex_ptr =3D (struct ex_list *)malloc(sizeof(struct ex_list)); + *ex_ptr =3D g_new(struct ex_list, 1); (*ex_ptr)->ex_fport =3D port; (*ex_ptr)->ex_addr =3D addr; (*ex_ptr)->ex_pty =3D do_pty; - (*ex_ptr)->ex_exec =3D (do_pty =3D=3D 3) ? exec : strdup(exec); + (*ex_ptr)->ex_exec =3D (do_pty =3D=3D 3) ? exec : g_strdup(exec); (*ex_ptr)->ex_next =3D tmp_ptr; return 0; } @@ -187,7 +187,7 @@ fork_exec(struct socket *so, const char *ex, int do_p= ty) bptr++; c =3D *bptr; *bptr++ =3D (char)0; - argv[i++] =3D strdup(curarg); + argv[i++] =3D g_strdup(curarg); } while (c); =20 argv[i] =3D NULL; @@ -228,20 +228,6 @@ fork_exec(struct socket *so, const char *ex, int do_= pty) } #endif =20 -#ifndef HAVE_STRDUP -char * -strdup(str) - const char *str; -{ - char *bptr; - - bptr =3D (char *)malloc(strlen(str)+1); - strcpy(bptr, str); - - return bptr; -} -#endif - void slirp_connection_info(Slirp *slirp, Monitor *mon) { const char * const tcpstates[] =3D { diff --git a/slirp/misc.h b/slirp/misc.h index ba8beb1..41a3258 100644 --- a/slirp/misc.h +++ b/slirp/misc.h @@ -16,10 +16,6 @@ struct ex_list { struct ex_list *ex_next; }; =20 -#ifndef HAVE_STRDUP -char *strdup(const char *); -#endif - #define EMU_NONE 0x0 =20 /* TCP emulations */ diff --git a/slirp/slirp_config.h b/slirp/slirp_config.h index 18db45c..896d802 100644 --- a/slirp/slirp_config.h +++ b/slirp/slirp_config.h @@ -72,9 +72,6 @@ /* Define if you have strerror */ #define HAVE_STRERROR =20 -/* 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 --=20 1.7.10.4