xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Ian Campbell <ian.campbell@citrix.com>
To: xen-devel@lists.xensource.com
Cc: Ian Campbell <ian.campbell@citrix.com>
Subject: [PATCH 2 of 3] libxl: fix memory leak in libxl_name_to_domid
Date: Mon, 02 Aug 2010 13:31:12 +0100	[thread overview]
Message-ID: <2a932193a3fac4f861f0.1280752272@localhost.localdomain> (raw)
In-Reply-To: <patchbomb.1280752270@localhost.localdomain>

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1280752237 -3600
# Node ID 2a932193a3fac4f861f0c6353a2d251077012a61
# Parent  b3e1074b137c03131cea33c5100cbc2fa6cc5d5f
libxl: fix memory leak in libxl_name_to_domid

Found with "valgrind xl destroy ...":
==16272== 53,248 bytes in 1 blocks are definitely lost in loss record 6 of 6
==16272==    at 0x4022249: calloc (vg_replace_malloc.c:467)
==16272==    by 0x403FD4A: libxl_list_domain (libxl.c:490)
==16272==    by 0x404B901: libxl_name_to_domid (libxl_utils.c:65)
==16272==    by 0x804B4D2: domain_qualifier_to_domid (xl_cmdimpl.c:181)
==16272==    by 0x804B50F: find_domain (xl_cmdimpl.c:198)
==16272==    by 0x804D70C: destroy_domain (xl_cmdimpl.c:2104)
==16272==    by 0x8054E4C: main_destroy (xl_cmdimpl.c:2912)
==16272==    by 0x804B2FB: main (xl.c:76)

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r b3e1074b137c -r 2a932193a3fa tools/libxl/libxl_utils.c
--- a/tools/libxl/libxl_utils.c	Mon Aug 02 13:30:37 2010 +0100
+++ b/tools/libxl/libxl_utils.c	Mon Aug 02 13:30:37 2010 +0100
@@ -61,6 +61,7 @@ int libxl_name_to_domid(libxl_ctx *ctx, 
     int i, nb_domains;
     char *domname;
     libxl_dominfo *dominfo;
+    int ret = -1;
 
     dominfo = libxl_list_domain(ctx, &nb_domains);
     if (!dominfo)
@@ -72,10 +73,12 @@ int libxl_name_to_domid(libxl_ctx *ctx, 
             continue;
         if (strcmp(domname, name) == 0) {
             *domid = dominfo[i].domid;
-            return 0;
+            ret = 0;
+            break;
         }
     }
-    return -1;
+    free(dominfo);
+    return ret;
 }
 
 char *libxl_poolid_to_name(libxl_ctx *ctx, uint32_t poolid)

  parent reply	other threads:[~2010-08-02 12:31 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-02 12:31 [PATCH 0 of 3] libxl: memory leaks Ian Campbell
2010-08-02 12:31 ` [PATCH 1 of 3] libxc: free thread specific hypercall buffer on xc_interface_close Ian Campbell
2010-08-02 12:31 ` Ian Campbell [this message]
2010-08-02 12:31 ` [PATCH 3 of 3] xl: fix memory leaks in xl create Ian Campbell
2010-08-02 13:11 ` [PATCH 0 of 3] libxl: memory leaks Gianni Tedesco
2010-08-02 13:20   ` Vincent Hanquez
2010-08-02 14:05     ` Gianni Tedesco
2010-08-03  7:59       ` Vincent Hanquez
2010-08-03 10:18         ` Gianni Tedesco
2010-08-03 10:51           ` Vincent Hanquez
2010-08-03 12:16             ` Gianni Tedesco
2010-08-03 13:37               ` Vincent Hanquez
2010-08-03 14:02                 ` Gianni Tedesco
2010-08-03 14:51                 ` Ian Campbell
2010-08-03 17:07                   ` Stefano Stabellini
2010-08-03 17:11 ` Stefano Stabellini

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=2a932193a3fac4f861f0.1280752272@localhost.localdomain \
    --to=ian.campbell@citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /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).