# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1280752237 -3600
# Node ID e2e90fac665ede04ef44d16c7df82f12b55f3931
# Parent 2a932193a3fac4f861f0c6353a2d251077012a61
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>
diff -r 2a932193a3fa -r e2e90fac665e tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c Mon Aug 02 13:30:37 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c Mon Aug 02 13:30:37 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-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|