WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 2 of 3] libxl: fix memory leak in libxl_name_to_domid

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 2 of 3] libxl: fix memory leak in libxl_name_to_domid
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Mon, 02 Aug 2010 13:31:12 +0100
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Delivery-date: Mon, 02 Aug 2010 05:34:45 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1280752270@xxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# 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@xxxxxxxxxx>

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)

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel