debuggers.hg

changeset 22083:f7d818754afb

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)

[PATCH 10 of 16 of
libxl: autogenerate type definitions and destructor functions]

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

==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)
author Ian Campbell <ian.campbell@citrix.com>
date Thu Aug 19 15:29:57 2010 +0100 (2010-08-19)
parents ed717f785082
children 5aa4671f4fa4
files tools/libxl/xl_cmdimpl.c
line diff
     1.1 --- a/tools/libxl/xl_cmdimpl.c	Thu Aug 19 15:25:15 2010 +0100
     1.2 +++ b/tools/libxl/xl_cmdimpl.c	Thu Aug 19 15:29:57 2010 +0100
     1.3 @@ -144,12 +144,34 @@ struct domain_config {
     1.4  
     1.5  static void free_domain_config(struct domain_config *d_config)
     1.6  {
     1.7 +    int i;
     1.8 +
     1.9 +    for (i=0; i<d_config->num_disks; i++)
    1.10 +        libxl_device_disk_destroy(&d_config->disks[i]);
    1.11      free(d_config->disks);
    1.12 +
    1.13 +    for (i=0; i<d_config->num_vifs; i++)
    1.14 +        libxl_device_nic_destroy(&d_config->vifs[i]);
    1.15      free(d_config->vifs);
    1.16 +
    1.17 +    for (i=0; i<d_config->num_vif2s; i++)
    1.18 +        libxl_device_net2_destroy(&d_config->vif2s[i]);
    1.19      free(d_config->vif2s);
    1.20 +
    1.21 +    for (i=0; i<d_config->num_pcidevs; i++)
    1.22 +        libxl_device_pci_destroy(&d_config->pcidevs[i]);
    1.23      free(d_config->pcidevs);
    1.24 +
    1.25 +    for (i=0; i<d_config->num_vfbs; i++)
    1.26 +        libxl_device_vfb_destroy(&d_config->vfbs[i]);
    1.27      free(d_config->vfbs);
    1.28 +
    1.29 +    for (i=0; i<d_config->num_vkbs; i++)
    1.30 +        libxl_device_vkb_destroy(&d_config->vkbs[i]);
    1.31      free(d_config->vkbs);
    1.32 +
    1.33 +    libxl_domain_create_info_destroy(&d_config->c_info);
    1.34 +    libxl_domain_build_info_destroy(&d_config->b_info);
    1.35  }
    1.36  
    1.37  /* Optional data, in order:
    1.38 @@ -309,7 +331,7 @@ static void init_nic_info(libxl_device_n
    1.39      nic_info->domid = 0;
    1.40      nic_info->devid = devnum;
    1.41      nic_info->mtu = 1492;
    1.42 -    nic_info->model = "e1000";
    1.43 +    nic_info->model = strdup("e1000");
    1.44      nic_info->mac[0] = 0x00;
    1.45      nic_info->mac[1] = 0x16;
    1.46      nic_info->mac[2] = 0x3e;
    1.47 @@ -317,7 +339,7 @@ static void init_nic_info(libxl_device_n
    1.48      nic_info->mac[4] = 1 + (int) (0xff * (rand() / (RAND_MAX + 1.0)));
    1.49      nic_info->mac[5] = 1 + (int) (0xff * (rand() / (RAND_MAX + 1.0)));
    1.50      nic_info->ifname = NULL;
    1.51 -    nic_info->bridge = "xenbr0";
    1.52 +    nic_info->bridge = strdup("xenbr0");
    1.53      CHK_ERRNO( asprintf(&nic_info->script, "%s/vif-bridge",
    1.54                 libxl_xen_script_dir_path()) );
    1.55      nic_info->nictype = NICTYPE_IOEMU;
    1.56 @@ -796,6 +818,7 @@ static void parse_config_data(const char
    1.57                      break;
    1.58                  *p2 = '\0';
    1.59                  if (!strcmp(p, "model")) {
    1.60 +                    free(nic->model);
    1.61                      nic->model = strdup(p2 + 1);
    1.62                  } else if (!strcmp(p, "mac")) {
    1.63                      char *p3 = p2 + 1;
    1.64 @@ -817,6 +840,7 @@ static void parse_config_data(const char
    1.65                      *(p3 + 2) = '\0';
    1.66                      nic->mac[5] = strtol(p3, NULL, 16);
    1.67                  } else if (!strcmp(p, "bridge")) {
    1.68 +                    free(nic->bridge);
    1.69                      nic->bridge = strdup(p2 + 1);
    1.70                  } else if (!strcmp(p, "type")) {
    1.71                      if (!strcmp(p2 + 1, "ioemu"))