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 8 of 8] xl: free the libxl types contained in struct domain_config
Date: Tue, 03 Aug 2010 12:00:23 +0100	[thread overview]
Message-ID: <e977c80592ca15c3bb42.1280833223@localhost.localdomain> (raw)
In-Reply-To: <patchbomb.1280833215@localhost.localdomain>

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1280829842 -3600
# Node ID e977c80592ca15c3bb42edf0a4fcdeb3794543f2
# Parent  6baa8ce2ec5ed5d140a67b87d2514e88464df34e
xl: free the libxl types contained in struct domain_config

Resolves the following leaks found using "valgrind xl create -n ..."
(plus presumably others which didn't trigger because I have no devices
of that type)

==21241== 5 bytes in 1 blocks are definitely lost in loss record 1 of 6
==21241==    at 0x4022F0A: malloc (vg_replace_malloc.c:236)
==21241==    by 0x411B22F: strdup (in /lib/i686/cmov/libc-2.7.so)
==21241==    by 0x804E56B: parse_config_data (xl_cmdimpl.c:760)
==21241==    by 0x8056B04: create_domain (xl_cmdimpl.c:1357)
==21241==    by 0x8057ECE: main_create (xl_cmdimpl.c:3154)
==21241==    by 0x804B2FB: main (xl.c:76)
==21241==
==21241== 6 bytes in 1 blocks are definitely lost in loss record 2 of 6
==21241==    at 0x4022F0A: malloc (vg_replace_malloc.c:236)
==21241==    by 0x411B22F: strdup (in /lib/i686/cmov/libc-2.7.so)
==21241==    by 0x804DAAA: parse_config_data (xl_cmdimpl.c:586)
==21241==    by 0x8056B04: create_domain (xl_cmdimpl.c:1357)
==21241==    by 0x8057ECE: main_create (xl_cmdimpl.c:3154)
==21241==    by 0x804B2FB: main (xl.c:76)
==21241==
==21241== 24 bytes in 1 blocks are definitely lost in loss record 3 of 6
==21241==    at 0x4022F0A: malloc (vg_replace_malloc.c:236)
==21241==    by 0x411B22F: strdup (in /lib/i686/cmov/libc-2.7.so)
==21241==    by 0x804E51F: parse_config_data (xl_cmdimpl.c:754)
==21241==    by 0x8056B04: create_domain (xl_cmdimpl.c:1357)
==21241==    by 0x8057ECE: main_create (xl_cmdimpl.c:3154)
==21241==    by 0x804B2FB: main (xl.c:76)
==21241==
==21241== 27 bytes in 1 blocks are definitely lost in loss record 4 of 6
==21241==    at 0x4022F0A: malloc (vg_replace_malloc.c:236)
==21241==    by 0x411B22F: strdup (in /lib/i686/cmov/libc-2.7.so)
==21241==    by 0x804DF4A: parse_config_data (xl_cmdimpl.c:664)
==21241==    by 0x8056B04: create_domain (xl_cmdimpl.c:1357)
==21241==    by 0x8057ECE: main_create (xl_cmdimpl.c:3154)
==21241==    by 0x804B2FB: main (xl.c:76)
==21241==
==21241== 28 bytes in 1 blocks are definitely lost in loss record 5 of 6
==21241==    at 0x4022F0A: malloc (vg_replace_malloc.c:236)
==21241==    by 0x410C1A7: vasprintf (in /lib/i686/cmov/libc-2.7.so)
==21241==    by 0x40EE59A: asprintf (in /lib/i686/cmov/libc-2.7.so)
==21241==    by 0x804CA8B: init_nic_info (xl_cmdimpl.c:322)
==21241==    by 0x804E6FF: parse_config_data (xl_cmdimpl.c:791)
==21241==    by 0x8056B04: create_domain (xl_cmdimpl.c:1357)
==21241==    by 0x8057ECE: main_create (xl_cmdimpl.c:3154)
==21241==    by 0x804B2FB: main (xl.c:76)
==21241==
==21241== 44 bytes in 1 blocks are definitely lost in loss record 6 of 6
==21241==    at 0x4022F0A: malloc (vg_replace_malloc.c:236)
==21241==    by 0x411B22F: strdup (in /lib/i686/cmov/libc-2.7.so)
==21241==    by 0x804E168: parse_config_data (xl_cmdimpl.c:694)
==21241==    by 0x8056B04: create_domain (xl_cmdimpl.c:1357)
==21241==    by 0x8057ECE: main_create (xl_cmdimpl.c:3154)
==21241==    by 0x804B2FB: main (xl.c:76)

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

diff -r 6baa8ce2ec5e -r e977c80592ca tools/libxl/libxl_utils.c
--- a/tools/libxl/libxl_utils.c	Tue Aug 03 10:59:46 2010 +0100
+++ b/tools/libxl/libxl_utils.c	Tue Aug 03 11:04:02 2010 +0100
@@ -81,7 +81,7 @@ int libxl_name_to_domid(libxl_ctx *ctx, 
     return ret;
 }
 
-char *libxl_poolid_to_name(libxl_ctx *ctx, uint32_t poolid)
+const char *libxl_poolid_to_name(libxl_ctx *ctx, uint32_t poolid)
 {
     unsigned int len;
     char path[strlen("/local/pool") + 12];
@@ -99,7 +99,7 @@ int libxl_name_to_poolid(libxl_ctx *ctx,
                         uint32_t *poolid)
 {
     int i, nb_pools;
-    char *poolname;
+    const char *poolname;
     libxl_poolinfo *poolinfo;
 
     poolinfo = libxl_list_pool(ctx, &nb_pools);
diff -r 6baa8ce2ec5e -r e977c80592ca tools/libxl/libxl_utils.h
--- a/tools/libxl/libxl_utils.h	Tue Aug 03 10:59:46 2010 +0100
+++ b/tools/libxl/libxl_utils.h	Tue Aug 03 11:04:02 2010 +0100
@@ -22,7 +22,7 @@ int libxl_name_to_domid(libxl_ctx *ctx, 
 int libxl_name_to_domid(libxl_ctx *ctx, const char *name, uint32_t *domid);
 char *libxl_domid_to_name(libxl_ctx *ctx, uint32_t domid);
 int libxl_name_to_poolid(libxl_ctx *ctx, const char *name, uint32_t *poolid);
-char *libxl_poolid_to_name(libxl_ctx *ctx, uint32_t poolid);
+const char *libxl_poolid_to_name(libxl_ctx *ctx, uint32_t poolid);
 int libxl_get_stubdom_id(libxl_ctx *ctx, int guest_domid);
 int libxl_is_stubdom(libxl_ctx *ctx, uint32_t domid, uint32_t *target_domid);
 int libxl_create_logfile(libxl_ctx *ctx, char *name, char **full_name);
diff -r 6baa8ce2ec5e -r e977c80592ca tools/libxl/libxltypes.py
--- a/tools/libxl/libxltypes.py	Tue Aug 03 10:59:46 2010 +0100
+++ b/tools/libxl/libxltypes.py	Tue Aug 03 11:04:02 2010 +0100
@@ -232,7 +232,7 @@ libxl_domain_create_info = Struct("domai
     ("xsdata",       KeyValueList(string, string)),
     ("platformdata", KeyValueList(string, string)),
     ("poolid",       uint32),
-    ("poolname",     string),
+    ("poolname",     string, True),
     ])
 
 libxl_domain_build_info = Struct("domain_build_info",[
diff -r 6baa8ce2ec5e -r e977c80592ca tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c	Tue Aug 03 10:59:46 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c	Tue Aug 03 11:04:02 2010 +0100
@@ -145,12 +145,34 @@ struct domain_config {
 
 static void free_domain_config(struct domain_config *d_config)
 {
+    int i;
+
+    for (i=0; i<d_config->num_disks; i++)
+        libxl_device_disk_destroy(&d_config->disks[i]);
     free(d_config->disks);
+
+    for (i=0; i<d_config->num_vifs; i++)
+        libxl_device_nic_destroy(&d_config->vifs[i]);
     free(d_config->vifs);
+
+    for (i=0; i<d_config->num_vif2s; i++)
+        libxl_device_net2_destroy(&d_config->vif2s[i]);
     free(d_config->vif2s);
+
+    for (i=0; i<d_config->num_pcidevs; i++)
+        libxl_device_pci_destroy(&d_config->pcidevs[i]);
     free(d_config->pcidevs);
+
+    for (i=0; i<d_config->num_vfbs; i++)
+        libxl_device_vfb_destroy(&d_config->vfbs[i]);
     free(d_config->vfbs);
+
+    for (i=0; i<d_config->num_vkbs; i++)
+        libxl_device_vkb_destroy(&d_config->vkbs[i]);
     free(d_config->vkbs);
+
+    libxl_domain_create_info_destroy(&d_config->c_info);
+    libxl_domain_build_info_destroy(&d_config->b_info);
 }
 
 /* Optional data, in order:
@@ -310,7 +332,7 @@ static void init_nic_info(libxl_device_n
     nic_info->domid = 0;
     nic_info->devid = devnum;
     nic_info->mtu = 1492;
-    nic_info->model = "e1000";
+    nic_info->model = strdup("e1000");
     nic_info->mac[0] = 0x00;
     nic_info->mac[1] = 0x16;
     nic_info->mac[2] = 0x3e;
@@ -318,7 +340,7 @@ static void init_nic_info(libxl_device_n
     nic_info->mac[4] = 1 + (int) (0xff * (rand() / (RAND_MAX + 1.0)));
     nic_info->mac[5] = 1 + (int) (0xff * (rand() / (RAND_MAX + 1.0)));
     nic_info->ifname = NULL;
-    nic_info->bridge = "xenbr0";
+    nic_info->bridge = strdup("xenbr0");
     CHK_ERRNO( asprintf(&nic_info->script, "%s/vif-bridge",
                libxl_xen_script_dir_path()) );
     nic_info->nictype = NICTYPE_IOEMU;
@@ -800,6 +822,7 @@ static void parse_config_data(const char
                     break;
                 *p2 = '\0';
                 if (!strcmp(p, "model")) {
+                    free(nic->model);
                     nic->model = strdup(p2 + 1);
                 } else if (!strcmp(p, "mac")) {
                     char *p3 = p2 + 1;
@@ -821,6 +844,7 @@ static void parse_config_data(const char
                     *(p3 + 2) = '\0';
                     nic->mac[5] = strtol(p3, NULL, 16);
                 } else if (!strcmp(p, "bridge")) {
+                    free(nic->bridge);
                     nic->bridge = strdup(p2 + 1);
                 } else if (!strcmp(p, "type")) {
                     if (!strcmp(p2 + 1, "ioemu"))

  parent reply	other threads:[~2010-08-03 11:00 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-03 11:00 [PATCH 0 of 8] [RFC] libxl: autogenerate type definitions and destructor functions Ian Campbell
2010-08-03 11:00 ` [PATCH 1 of 8] libxl: add a specific UUID type Ian Campbell
2010-08-03 11:00 ` [PATCH 2 of 8] libxl: add a specific MAC address type Ian Campbell
2010-08-03 11:00 ` [PATCH 3 of 8] libxl: move type definitions into _libxl_types.h Ian Campbell
2010-08-03 11:00 ` [PATCH 4 of 8] libxl: tweak formatting/whitespace of _libxl_types.h Ian Campbell
2010-08-03 11:00 ` [PATCH 5 of 8] libxl: autogenerate _libxl_types.h Ian Campbell
2010-08-03 12:13   ` Gianni Tedesco
2010-08-03 12:29     ` Ian Campbell
2010-08-03 12:36       ` Gianni Tedesco
2010-08-03 13:30       ` Ian Campbell
2010-08-03 11:00 ` [PATCH 6 of 8] libxl: add KeyedUnion type Ian Campbell
2010-08-03 11:00 ` [PATCH 7 of 8] libxl: generate destructors for each libxl defined type Ian Campbell
2010-08-03 12:07   ` Gianni Tedesco
2010-08-03 12:24     ` Ian Campbell
2010-08-03 12:34       ` Gianni Tedesco
2010-08-03 11:00 ` Ian Campbell [this message]
2010-08-04 10:25 ` [PATCH 0 of 8] [RFC] libxl: autogenerate type definitions and destructor functions Gianni Tedesco
2010-08-04 17:16 ` Stefano Stabellini
2010-08-10 14:41   ` Ian Jackson
2010-08-10 14:48     ` 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=e977c80592ca15c3bb42.1280833223@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).