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 v3 10/10] libxl: fix caller of libxl_cpupool functions
Date: Tue, 14 Jul 2015 17:41:13 +0100	[thread overview]
Message-ID: <1436892073-14186-11-git-send-email-wei.liu2@citrix.com> (raw)
In-Reply-To: <1436892073-14186-1-git-send-email-wei.liu2@citrix.com>

Coverity complains cpupool_info leaks a string in failure path. Instead
of fixing that path, we rely on the callers (two public APIs at the
moment) of cpupool_info correctly call libxl_cpupoolinfo_dispose in
their failure path to dispose of any resources.

That involves:
1. Call _init and _dispose in libxl_list_cpupool
2. Call _init in numa_place_domain

Fix numa_place_domain to use goto style to make things more clearer.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: Dario Faggioli <dario.faggioli@citrix.com>
---
 tools/libxl/libxl.c     | 6 +++++-
 tools/libxl/libxl_dom.c | 5 +++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 38aff8d..02b4a26 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -771,8 +771,11 @@ libxl_cpupoolinfo * libxl_list_cpupool(libxl_ctx *ctx, int *nb_pool_out)
 
     poolid = 0;
     for (i = 0;; i++) {
-        if (cpupool_info(gc, &info, poolid, false))
+        libxl_cpupoolinfo_init(&info);
+        if (cpupool_info(gc, &info, poolid, false)) {
+            libxl_cpupoolinfo_dispose(&info);
             break;
+        }
         tmp = realloc(ptr, (i + 1) * sizeof(libxl_cpupoolinfo));
         if (!tmp) {
             LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "allocating cpupool info");
@@ -783,6 +786,7 @@ libxl_cpupoolinfo * libxl_list_cpupool(libxl_ctx *ctx, int *nb_pool_out)
         ptr = tmp;
         ptr[i] = info;
         poolid = info.poolid + 1;
+        /* Don't dispose of info. It needs to be returned to caller. */
     }
 
     *nb_pool_out = i;
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index 8642192..26e7c67 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -142,6 +142,7 @@ static int numa_place_domain(libxl__gc *gc, uint32_t domid,
 
     libxl__numa_candidate_init(&candidate);
     libxl_bitmap_init(&cpupool_nodemap);
+    libxl_cpupoolinfo_init(&cpupool_info);
 
     /*
      * Extract the cpumap from the cpupool the domain belong to. In fact,
@@ -150,10 +151,10 @@ static int numa_place_domain(libxl__gc *gc, uint32_t domid,
      */
     rc = cpupool = libxl__domain_cpupool(gc, domid);
     if (rc < 0)
-        return rc;
+        goto out;
     rc = libxl_cpupool_info(CTX, &cpupool_info, cpupool);
     if (rc)
-        return rc;
+        goto out;
 
     rc = libxl_domain_need_memory(CTX, info, &memkb);
     if (rc)
-- 
1.9.1

  parent reply	other threads:[~2015-07-14 16:45 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-14 16:41 [PATCH v3 00/10] xl/libxl: fix issues discovered by coverity Wei Liu
2015-07-14 16:41 ` [PATCH v3 01/10] libxl: don't check s!=NULL in libxl__abs_path Wei Liu
2015-07-14 17:19   ` Ian Jackson
2015-07-14 16:41 ` [PATCH v3 02/10] libxl: turn two malloc's to libxl__malloc Wei Liu
2015-07-14 17:19   ` Ian Jackson
2015-07-14 16:41 ` [PATCH v3 03/10] libxl: make libxl__strdup handle NULL Wei Liu
2015-07-14 17:21   ` Ian Jackson
2015-07-14 16:41 ` [PATCH v3 04/10] libxl: avoid leaking in libxl__initia_device_remove Wei Liu
2015-07-14 17:21   ` Ian Jackson
2015-07-14 16:41 ` [PATCH v3 05/10] libxl: localtime(3) can return NULL Wei Liu
2015-07-14 17:22   ` Ian Jackson
2015-07-14 16:41 ` [PATCH v3 06/10] libxl: qmp_init_handler " Wei Liu
2015-07-14 17:23   ` Ian Jackson
2015-07-14 16:41 ` [PATCH v3 07/10] xl: correct handling of extra_config in main_cpupoolcreate Wei Liu
2015-07-14 17:23   ` Ian Jackson
2015-09-11 10:59   ` Ian Jackson
2015-07-14 16:41 ` [PATCH v3 08/10] xl: correctly handle null extra config in main_config_update Wei Liu
2015-07-14 17:23   ` Ian Jackson
2015-07-14 16:41 ` [PATCH v3 09/10] xl: fix a typo in error string in create_domain Wei Liu
2015-07-14 17:24   ` Ian Jackson
2015-07-14 16:41 ` Wei Liu [this message]
2015-07-14 17:33   ` [PATCH v3 10/10] libxl: fix caller of libxl_cpupool functions Ian Jackson
2015-07-15 17:16     ` Wei Liu
2015-07-16  8:57       ` Dario Faggioli
2015-07-16  9:07         ` Wei Liu
2015-07-16  9:33           ` Juergen Gross
2015-07-16  9:30         ` Juergen Gross
2015-07-16 12:49           ` Dario Faggioli
2015-07-15 10:23 ` [PATCH v3 00/10] xl/libxl: fix issues discovered by coverity Ian Campbell

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=1436892073-14186-11-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).