xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Wei Liu <wei.liu2@citrix.com>
To: Xen-devel <xen-devel@lists.xenproject.org>
Cc: Wei Liu <wei.liu2@citrix.com>,
	Ian Jackson <Ian.Jackson@eu.citrix.com>,
	Ian Campbell <ian.campbell@citrix.com>
Subject: [PATCH v2 02/10] libxl: turn two malloc's to libxl__malloc
Date: Mon, 13 Jul 2015 17:22:13 +0100	[thread overview]
Message-ID: <1436804541-12965-3-git-send-email-wei.liu2@citrix.com> (raw)
In-Reply-To: <1436804541-12965-1-git-send-email-wei.liu2@citrix.com>

One is to combine malloc + libxl__alloc_failed. The other is to avoid
dereferencing NULL pointer in case of malloc failure.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
 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) {
-- 
1.9.1

  parent reply	other threads:[~2015-07-13 16:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-13 16:22 [PATCH v2 00/10] xl/libxl: fix issues discovered by coverity Wei Liu
2015-07-13 16:22 ` [PATCH v2 01/10] libxl: make libxl__abs_path correctly handle NULL argument Wei Liu
2015-07-13 16:22 ` Wei Liu [this message]
2015-07-13 17:15   ` [PATCH v2 02/10] libxl: turn two malloc's to libxl__malloc Ian Jackson
2015-07-13 16:22 ` [PATCH v2 03/10] libxl: json string object can be NULL Wei Liu
2015-07-13 16:22 ` [PATCH v2 04/10] libxl: dispose dominfo to avoid leaking resource Wei Liu
2015-07-13 16:22 ` [PATCH v2 05/10] libxl: localtime(3) can return NULL Wei Liu
2015-07-13 16:22 ` [PATCH v2 06/10] libxl: qmp_init_handler " Wei Liu
2015-07-13 16:22 ` [PATCH v2 07/10] xl: correct handling of extra_config in main_cpupoolcreate Wei Liu
2015-07-13 16:22 ` [PATCH v2 08/10] xl: correctly handle null extra config in main_config_update Wei Liu
2015-07-13 16:22 ` [PATCH v2 09/10] xl: fix a typo in error string in create_domain Wei Liu
2015-07-13 16:22 ` [PATCH v2 10/10] libxl: fix caller of libxl_cpupool functions Wei Liu
2015-07-14  9:37   ` Dario Faggioli

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=1436804541-12965-3-git-send-email-wei.liu2@citrix.com \
    --to=wei.liu2@citrix.com \
    --cc=Ian.Jackson@eu.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).