From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54366) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XFgi3-0008KS-Uu for qemu-devel@nongnu.org; Fri, 08 Aug 2014 05:43:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XFghw-0002g1-B6 for qemu-devel@nongnu.org; Fri, 08 Aug 2014 05:43:39 -0400 Received: from static.88-198-71-155.clients.your-server.de ([88.198.71.155]:35055 helo=socrates.bennee.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XFghw-0002ev-5S for qemu-devel@nongnu.org; Fri, 08 Aug 2014 05:43:32 -0400 References: <1407489672-12212-1-git-send-email-zhang.zhanghailiang@huawei.com> <1407489672-12212-6-git-send-email-zhang.zhanghailiang@huawei.com> From: Alex =?utf-8?Q?Benn=C3=A9e?= Date: Fri, 08 Aug 2014 10:36:11 +0100 In-reply-to: <1407489672-12212-6-git-send-email-zhang.zhanghailiang@huawei.com> Message-ID: <87oavvjozf.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH v4 05/10] util/path: check return value of malloc() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: zhanghailiang Cc: kwolf@redhat.com, lkurusa@redhat.com, mst@redhat.com, jan.kiszka@siemens.com, riku.voipio@iki.fi, mjt@tls.msk.ru, qemu-devel@nongnu.org, lcapitulino@redhat.com, stefanha@redhat.com, luonengjun@huawei.com, pbonzini@redhat.com, peter.huangpeng@huawei.com, rth@twiddle.net zhanghailiang writes: > Reviewed-by: Gonglei > Signed-off-by: zhanghailiang > --- > util/path.c | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/util/path.c b/util/path.c > index 5c59d9f..df1653f 100644 > --- a/util/path.c > +++ b/util/path.c > @@ -46,9 +46,12 @@ static struct pathelem *new_entry(const char *root, > const char *name) > { > struct pathelem *new = malloc(sizeof(*new)); > - new->name = strdup(name); > - new->pathname = g_strdup_printf("%s/%s", root, name); > - new->num_entries = 0; Erm... isn't that malloc wrong as sizeof(*new) would be the size of a pointer? > + > + if (new) { > + new->name = strdup(name); > + new->pathname = g_strdup_printf("%s/%s", root, name); > + new->num_entries = 0; > + } > return new; > } A better approach may be to just g_malloc which would abort on failure (which would be fine for setup). static struct pathelem *new_entry(const char *root, struct pathelem *parent, const char *name) { struct pathelem *new = g_malloc(sizeof(pathelem)); new->name = g_strdup(name); new->pathname = g_strdup_printf("%s/%s", root, name); new->num_entries = 0; return new; } -- Alex Bennée