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-changelog

[Xen-changelog] [xen-unstable] xl: fix memory leaks in xl create

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] xl: fix memory leaks in xl create
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Thu, 05 Aug 2010 01:35:19 -0700
Delivery-date: Thu, 05 Aug 2010 01:36:18 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1280855428 -3600
# Node ID d7ec0e180601228f92d9d46d822e8ebeaf8bf803
# Parent  f6b91d2f9fa3437c37b17ad7b6d4d334217a6ba5
xl: fix memory leaks in xl create

Found using "valgrind xl create -n ..." and "valgrind xl create -e ..."

freeing config_data solves:
==18276== 944 bytes in 1 blocks are definitely lost in loss record 12 of 12
==18276==    at 0x4022F0A: malloc (vg_replace_malloc.c:236)
==18276==    by 0x404AEC1: libxl_read_file_contents (libxl_utils.c:258)
==18276==    by 0x8056865: create_domain (xl_cmdimpl.c:1314)
==18276==    by 0x8057E2D: main_create (xl_cmdimpl.c:3135)
==18276==    by 0x804B2FB: main (xl.c:76)
==18276==

Adding free_domain_config() solves the following (plus presumably others
which didn't trigger because I have no devices of that type).

d_config->disks:
==18276== 61 (32 direct, 29 indirect) bytes in 1 blocks are definitely lost in 
loss record 9 of 12
==18276==    at 0x4022F0A: malloc (vg_replace_malloc.c:236)
==18276==    by 0x4022F94: realloc (vg_replace_malloc.c:525)
==18276==    by 0x804E2D3: parse_config_data (xl_cmdimpl.c:715)
==18276==    by 0x8056A7C: create_domain (xl_cmdimpl.c:1347)
==18276==    by 0x8057E2D: main_create (xl_cmdimpl.c:3135)
==18276==    by 0x804B2FB: main (xl.c:76)

d_config->vifs:
==18276== 76 (48 direct, 28 indirect) bytes in 1 blocks are definitely lost in 
loss record 10 of 12
==18276==    at 0x4022F0A: malloc (vg_replace_malloc.c:236)
==18276==    by 0x4022F94: realloc (vg_replace_malloc.c:525)
==18276==    by 0x804E665: parse_config_data (xl_cmdimpl.c:779)
==18276==    by 0x8056A7C: create_domain (xl_cmdimpl.c:1347)
==18276==    by 0x8057E2D: main_create (xl_cmdimpl.c:3135)
==18276==    by 0x804B2FB: main (xl.c:76)

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
---
 tools/libxl/xl_cmdimpl.c |   23 +++++++++++++++++++++--
 1 files changed, 21 insertions(+), 2 deletions(-)

diff -r f6b91d2f9fa3 -r d7ec0e180601 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Tue Aug 03 18:09:21 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c  Tue Aug 03 18:10:28 2010 +0100
@@ -142,6 +142,16 @@ struct domain_config {
     enum action_on_shutdown on_watchdog;
     enum action_on_shutdown on_crash;
 };
+
+static void free_domain_config(struct domain_config *d_config)
+{
+    free(d_config->disks);
+    free(d_config->vifs);
+    free(d_config->vif2s);
+    free(d_config->pcidevs);
+    free(d_config->vfbs);
+    free(d_config->vkbs);
+}
 
 /* Optional data, in order:
  *   4 bytes uint32_t  config file size
@@ -1346,8 +1356,9 @@ static int create_domain(struct domain_c
 
     parse_config_data(config_file, config_data, config_len, &d_config, 
&dm_info);
 
+    ret = 0;
     if (dom_info->dryrun)
-        return 0;
+        goto out;
 
     if (migrate_fd >= 0) {
         if (d_config.c_info.name) {
@@ -1477,8 +1488,9 @@ start:
     if (!paused)
         libxl_domain_unpause(&ctx, domid);
 
+    ret = domid; /* caller gets success in parent */
     if (!daemonize)
-        return domid; /* caller gets success in parent */
+        goto out;
 
     if (need_daemon) {
         char *fullname, *name;
@@ -1605,6 +1617,12 @@ error_out:
 error_out:
     if (domid)
         libxl_domain_destroy(&ctx, domid, 0);
+out:
+
+    free_domain_config(&d_config);
+
+    free(config_data);
+
     return ret;
 }
 
@@ -2143,6 +2161,7 @@ void list_domains_details(const libxl_do
         memset(&d_config, 0x00, sizeof(d_config));
         parse_config_data(config_file, (char *)data, len, &d_config, &dm_info);
         printf_info(info[i].domid, &d_config, &dm_info);
+        free_domain_config(&d_config);
         free(data);
         free(config_file);
     }

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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] xl: fix memory leaks in xl create, Xen patchbot-unstable <=