From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wei Liu Subject: Re: [PATCH 2/9] libxl: turn two malloc's to libxl__malloc Date: Mon, 13 Jul 2015 16:29:28 +0100 Message-ID: <20150713152928.GP4108@zion.uk.xensource.com> References: <1436551257-28887-1-git-send-email-wei.liu2@citrix.com> <1436551257-28887-3-git-send-email-wei.liu2@citrix.com> <1436781615.7019.63.camel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZEffh-00043t-L4 for xen-devel@lists.xenproject.org; Mon, 13 Jul 2015 15:29:33 +0000 Content-Disposition: inline In-Reply-To: <1436781615.7019.63.camel@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Campbell Cc: Xen-devel , Wei Liu , Ian Jackson , Andrew Cooper List-Id: xen-devel@lists.xenproject.org On Mon, Jul 13, 2015 at 11:00:15AM +0100, Ian Campbell wrote: > On Fri, 2015-07-10 at 19:00 +0100, Wei Liu wrote: > > One is to combine malloc + libxl__alloc_failed. The other is to avoid > > dereferencing NULL pointer in case of malloc failure. > > The non-use of a gc for the latter in particular looks a bit suspicious > to me, but nonetheless this is an improvement: > There is a free() later in this function. I wanted to make this patch minimum so I didn't switch to using gc and delete that free. > > Signed-off-by: Wei Liu > > Acked-by: Ian Campbell Thanks. Wei. > > > --- > > tools/libxl/libxl_aoutils.c | 3 +-- > > tools/libxl/libxl_dm.c | 2 +- > > 2 files changed, 2 insertions(+), 3 deletions(-) > > > > diff --git a/tools/libxl/libxl_aoutils.c b/tools/libxl/libxl_aoutils.c > > index 0931eee..0300396 100644 > > --- a/tools/libxl/libxl_aoutils.c > > +++ b/tools/libxl/libxl_aoutils.c > > @@ -245,8 +245,7 @@ static void datacopier_readable(libxl__egc *egc, libxl__ev_fd *ev, > > > > buf = LIBXL_TAILQ_LAST(&dc->bufs, libxl__datacopier_bufs); > > if (!buf || buf->used >= sizeof(buf->buf)) { > > - buf = malloc(sizeof(*buf)); > > - if (!buf) libxl__alloc_failed(CTX, __func__, 1, sizeof(*buf)); > > + buf = libxl__malloc(NOGC, sizeof(*buf)); > > buf->used = 0; > > LIBXL_TAILQ_INSERT_TAIL(&dc->bufs, buf, entry); > > } > > diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c > > index ad434f0..0cc73be 100644 > > --- a/tools/libxl/libxl_dm.c > > +++ b/tools/libxl/libxl_dm.c > > @@ -1010,7 +1010,7 @@ static int libxl__write_stub_dmargs(libxl__gc *gc, > > i++; > > } > > dmargs_size++; > > - dmargs = (char *) malloc(dmargs_size); > > + dmargs = (char *) libxl__malloc(NOGC, dmargs_size); > > i = 1; > > dmargs[0] = '\0'; > > while (args[i] != NULL) { >