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 3 of 3] xl: fix memory leaks in xl create
Date: Mon, 02 Aug 2010 13:31:13 +0100	[thread overview]
Message-ID: <e2e90fac665ede04ef44.1280752273@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 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@citrix.com>

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);
     }

  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 ` [PATCH 2 of 3] libxl: fix memory leak in libxl_name_to_domid Ian Campbell
2010-08-02 12:31 ` Ian Campbell [this message]
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=e2e90fac665ede04ef44.1280752273@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).