Received: from eggs.gnu.org ([2001:4830:134:3::10]:48825) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XLXy2-0003c4-Qv for qemu-devel@nongnu.org; Sun, 24 Aug 2014 09:36:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XLXxy-0006kp-Oz for qemu-devel@nongnu.org; Sun, 24 Aug 2014 09:36:22 -0400 From: Michael Tokarev Date: Sun, 24 Aug 2014 17:30:52 +0400 Message-Id: <1408887062-30022-2-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 01/11] util/path: Use the GLib memory allocation routines 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 In this file, we don't check the return value of malloc/strdup/realloc wh= ich may fail. Instead of using these routines, we use the GLib memory APIs g_malloc/g_s= trdup/g_realloc. They will exit on allocation failure, so there is no need to test for fai= lure, which would be fine for setup. Signed-off-by: zhanghailiang Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Michael Tokarev --- util/path.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/util/path.c b/util/path.c index 5c59d9f..4e4877e 100644 --- a/util/path.c +++ b/util/path.c @@ -45,8 +45,8 @@ static struct pathelem *new_entry(const char *root, struct pathelem *parent, const char *name) { - struct pathelem *new =3D malloc(sizeof(*new)); - new->name =3D strdup(name); + struct pathelem *new =3D g_malloc(sizeof(*new)); + new->name =3D g_strdup(name); new->pathname =3D g_strdup_printf("%s/%s", root, name); new->num_entries =3D 0; return new; @@ -88,7 +88,7 @@ static struct pathelem *add_entry(struct pathelem *root= , const char *name, =20 root->num_entries++; =20 - root =3D realloc(root, sizeof(*root) + root =3D g_realloc(root, sizeof(*root) + sizeof(root->entries[0])*root->num_entries); e =3D &root->entries[root->num_entries-1]; =20 @@ -161,8 +161,8 @@ void init_paths(const char *prefix) base =3D add_dir_maybe(base); if (base->num_entries =3D=3D 0) { g_free(base->pathname); - free(base->name); - free(base); + g_free(base->name); + g_free(base); base =3D NULL; } else { set_parents(base, base); --=20 1.7.10.4