xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Wei Liu <wei.liu2@citrix.com>
To: Ian Campbell <ian.campbell@citrix.com>
Cc: Xen-devel <xen-devel@lists.xenproject.org>,
	Wei Liu <wei.liu2@citrix.com>,
	Ian Jackson <Ian.Jackson@eu.citrix.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>
Subject: Re: [PATCH 2/9] libxl: turn two malloc's to libxl__malloc
Date: Mon, 13 Jul 2015 16:29:28 +0100	[thread overview]
Message-ID: <20150713152928.GP4108@zion.uk.xensource.com> (raw)
In-Reply-To: <1436781615.7019.63.camel@citrix.com>

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 <wei.liu2@citrix.com>
> 
> Acked-by: Ian Campbell <ian.campbell@citrix.com>

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) {
> 

  reply	other threads:[~2015-07-13 15:29 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-10 18:00 [PATCH 0/9] xl/libxl: fix issues discovered by Coverity scan Wei Liu
2015-07-10 18:00 ` [PATCH 1/9] libxl: fix libxl__abs_path Wei Liu
2015-07-13  9:57   ` Ian Campbell
2015-07-13 10:00     ` Wei Liu
2015-07-13 17:12     ` Ian Jackson
2015-07-14  7:23       ` Ian Campbell
2015-07-14 10:23         ` Ian Jackson
2015-07-14 13:32           ` Ian Campbell
2015-07-14 13:58             ` Ian Jackson
2015-07-14 14:10               ` Ian Campbell
2015-07-14 15:50           ` Wei Liu
2015-07-10 18:00 ` [PATCH 2/9] libxl: turn two malloc's to libxl__malloc Wei Liu
2015-07-13 10:00   ` Ian Campbell
2015-07-13 15:29     ` Wei Liu [this message]
2015-07-10 18:00 ` [PATCH 3/9] libxl: json string object can be NULL Wei Liu
2015-07-13 10:02   ` Ian Campbell
2015-07-13 17:16     ` Ian Jackson
2015-07-10 18:00 ` [PATCH 4/9] libxl: dispose dominfo to avoid leaking resource Wei Liu
2015-07-13 10:05   ` Ian Campbell
2015-07-13 17:18     ` Ian Jackson
2015-07-10 18:00 ` [PATCH 5/9] libxl: avoid leaking string in cpupool_info Wei Liu
2015-07-13 10:07   ` Ian Campbell
2015-07-13 16:10     ` Wei Liu
2015-07-13 16:23       ` Ian Campbell
2015-07-13 16:24         ` Wei Liu
2015-07-10 18:00 ` [PATCH 6/9] libxl: localtime(3) can return NULL Wei Liu
2015-07-13 10:09   ` Ian Campbell
2015-07-10 18:00 ` [PATCH 7/9] libxl: qmp_init_handler " Wei Liu
2015-07-13 10:10   ` Ian Campbell
2015-07-10 18:00 ` [PATCH 8/9] xl: fix main_cpupoolcreate Wei Liu
2015-07-13 10:11   ` Ian Campbell
2015-07-10 18:00 ` [PATCH 9/9] xl: fix main_config_update Wei Liu
2015-07-13 10:12   ` Ian Campbell
2015-07-10 18:21 ` [PATCH 0/9] xl/libxl: fix issues discovered by Coverity scan Andrew Cooper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150713152928.GP4108@zion.uk.xensource.com \
    --to=wei.liu2@citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).