debuggers.hg

changeset 21954:f6b91d2f9fa3

libxl: fix memory leak in libxl_name_to_domid

Found with "valgrind xl destroy ...":
==16272== 53,248 bytes in 1 blocks are definitely lost in loss record 6 of 6
==16272== at 0x4022249: calloc (vg_replace_malloc.c:467)
==16272== by 0x403FD4A: libxl_list_domain (libxl.c:490)
==16272== by 0x404B901: libxl_name_to_domid (libxl_utils.c:65)
==16272== by 0x804B4D2: domain_qualifier_to_domid (xl_cmdimpl.c:181)
==16272== by 0x804B50F: find_domain (xl_cmdimpl.c:198)
==16272== by 0x804D70C: destroy_domain (xl_cmdimpl.c:2104)
==16272== by 0x8054E4C: main_destroy (xl_cmdimpl.c:2912)
==16272== by 0x804B2FB: main (xl.c:76)

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
author Ian Campbell <ian.campbell@citrix.com>
date Tue Aug 03 18:09:21 2010 +0100 (2010-08-03)
parents fd99dc9ab249
children d7ec0e180601
files tools/libxl/libxl_utils.c
line diff
     1.1 --- a/tools/libxl/libxl_utils.c	Tue Aug 03 17:41:03 2010 +0100
     1.2 +++ b/tools/libxl/libxl_utils.c	Tue Aug 03 18:09:21 2010 +0100
     1.3 @@ -61,6 +61,7 @@ int libxl_name_to_domid(libxl_ctx *ctx, 
     1.4      int i, nb_domains;
     1.5      char *domname;
     1.6      libxl_dominfo *dominfo;
     1.7 +    int ret = -1;
     1.8  
     1.9      dominfo = libxl_list_domain(ctx, &nb_domains);
    1.10      if (!dominfo)
    1.11 @@ -72,10 +73,12 @@ int libxl_name_to_domid(libxl_ctx *ctx, 
    1.12              continue;
    1.13          if (strcmp(domname, name) == 0) {
    1.14              *domid = dominfo[i].domid;
    1.15 -            return 0;
    1.16 +            ret = 0;
    1.17 +            break;
    1.18          }
    1.19      }
    1.20 -    return -1;
    1.21 +    free(dominfo);
    1.22 +    return ret;
    1.23  }
    1.24  
    1.25  char *libxl_poolid_to_name(libxl_ctx *ctx, uint32_t poolid)