[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen stable-4.2] xl: do not leak cpupool names.



commit c60b24d997f5718a26c8d337ad0497c86d2184b7
Author:     Ian Campbell <ian.campbell@xxxxxxxxxx>
AuthorDate: Fri Sep 14 10:02:50 2012 +0100
Commit:     Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
CommitDate: Tue Mar 18 16:06:21 2014 +0000

    xl: do not leak cpupool names.
    
    Valgrind reports:
    ==3076== 7 bytes in 1 blocks are definitely lost in loss record 1 of 1
    ==3076==    at 0x402458C: malloc (vg_replace_malloc.c:270)
    ==3076==    by 0x406F86D: libxl_cpupoolid_to_name (libxl_utils.c:102)
    ==3076==    by 0x8058742: parse_config_data (xl_cmdimpl.c:639)
    ==3076==    by 0x805BD56: create_domain (xl_cmdimpl.c:1838)
    ==3076==    by 0x805DAED: main_create (xl_cmdimpl.c:3903)
    ==3076==    by 0x804D39D: main (xl.c:285)
    
    And indeed there are several places where xl uses
    libxl_cpupoolid_to_name as a boolean to test if the pool name is
    valid and leaks the name if it is. Introduce an is_valid helper and
    use that instead.
    
    Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
    Acked-by: Juergen Gross<juergen.gross@xxxxxxxxxxxxxx>
    Committed-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
    (cherry picked from commit 10a194b1c57de7ddc9d4fce07e01f2cd7d0ca26a)
---
 tools/libxl/libxl_utils.c |   11 +++++++++++
 tools/libxl/libxl_utils.h |    1 +
 tools/libxl/xl_cmdimpl.c  |   16 ++++++++--------
 tools/libxl/xl_sxp.c      |    7 +++++--
 4 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c
index f7b44a0..55cd299 100644
--- a/tools/libxl/libxl_utils.c
+++ b/tools/libxl/libxl_utils.c
@@ -103,6 +103,17 @@ char *libxl_cpupoolid_to_name(libxl_ctx *ctx, uint32_t 
poolid)
     return s;
 }
 
+/* This is a bit horrid but without xs_exists it seems like the only way. */
+int libxl_cpupoolid_is_valid(libxl_ctx *ctx, uint32_t poolid)
+{
+    int ret;
+    char *s = libxl_cpupoolid_to_name(ctx, poolid);
+
+    ret = (s != NULL);
+    free(s);
+    return ret;
+}
+
 char *libxl__cpupoolid_to_name(libxl__gc *gc, uint32_t poolid)
 {
     char *s = libxl_cpupoolid_to_name(libxl__gc_owner(gc), poolid);
diff --git a/tools/libxl/libxl_utils.h b/tools/libxl/libxl_utils.h
index 8fee567..83aaac7 100644
--- a/tools/libxl/libxl_utils.h
+++ b/tools/libxl/libxl_utils.h
@@ -24,6 +24,7 @@ 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_cpupoolid(libxl_ctx *ctx, const char *name, uint32_t 
*poolid);
 char *libxl_cpupoolid_to_name(libxl_ctx *ctx, uint32_t poolid);
+int libxl_cpupoolid_is_valid(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, const char *name, char **full_name);
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 4af5812..5eadb16 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -636,7 +636,7 @@ static void parse_config_data(const char *config_source,
         c_info->poolid = -1;
         cpupool_qualifier_to_cpupoolid(buf, &c_info->poolid, NULL);
     }
-    if (!libxl_cpupoolid_to_name(ctx, c_info->poolid)) {
+    if (!libxl_cpupoolid_is_valid(ctx, c_info->poolid)) {
         fprintf(stderr, "Illegal pool specified\n");
         exit(1);
     }
@@ -4746,7 +4746,7 @@ static int sched_domain_output(libxl_scheduler sched, int 
(*output)(int),
 
     if (cpupool) {
         if (cpupool_qualifier_to_cpupoolid(cpupool, &poolid, NULL) ||
-            !libxl_cpupoolid_to_name(ctx, poolid)) {
+            !libxl_cpupoolid_is_valid(ctx, poolid)) {
             fprintf(stderr, "unknown cpupool \'%s\'\n", cpupool);
             return -ERROR_FAIL;
         }
@@ -4878,7 +4878,7 @@ int main_sched_credit(int argc, char **argv)
 
         if (cpupool) {
             if (cpupool_qualifier_to_cpupoolid(cpupool, &poolid, NULL) ||
-                !libxl_cpupoolid_to_name(ctx, poolid)) {
+                !libxl_cpupoolid_is_valid(ctx, poolid)) {
                 fprintf(stderr, "unknown cpupool \'%s\'\n", cpupool);
                 return -ERROR_FAIL;
             }
@@ -6305,7 +6305,7 @@ int main_cpupooldestroy(int argc, char **argv)
     pool = argv[optind];
 
     if (cpupool_qualifier_to_cpupoolid(pool, &poolid, NULL) ||
-        !libxl_cpupoolid_to_name(ctx, poolid)) {
+        !libxl_cpupoolid_is_valid(ctx, poolid)) {
         fprintf(stderr, "unknown cpupool \'%s\'\n", pool);
         return -ERROR_FAIL;
     }
@@ -6326,7 +6326,7 @@ int main_cpupoolrename(int argc, char **argv)
     pool = argv[optind++];
 
     if (cpupool_qualifier_to_cpupoolid(pool, &poolid, NULL) ||
-        !libxl_cpupoolid_to_name(ctx, poolid)) {
+        !libxl_cpupoolid_is_valid(ctx, poolid)) {
         fprintf(stderr, "unknown cpupool \'%s\'\n", pool);
         return -ERROR_FAIL;
     }
@@ -6363,7 +6363,7 @@ int main_cpupoolcpuadd(int argc, char **argv)
     }
 
     if (cpupool_qualifier_to_cpupoolid(pool, &poolid, NULL) ||
-        !libxl_cpupoolid_to_name(ctx, poolid)) {
+        !libxl_cpupoolid_is_valid(ctx, poolid)) {
         fprintf(stderr, "unknown cpupool \'%s\'\n", pool);
         return -ERROR_FAIL;
     }
@@ -6407,7 +6407,7 @@ int main_cpupoolcpuremove(int argc, char **argv)
     }
 
     if (cpupool_qualifier_to_cpupoolid(pool, &poolid, NULL) ||
-        !libxl_cpupoolid_to_name(ctx, poolid)) {
+        !libxl_cpupoolid_is_valid(ctx, poolid)) {
         fprintf(stderr, "unknown cpupool \'%s\'\n", pool);
         return -ERROR_FAIL;
     }
@@ -6450,7 +6450,7 @@ int main_cpupoolmigrate(int argc, char **argv)
     }
 
     if (cpupool_qualifier_to_cpupoolid(pool, &poolid, NULL) ||
-        !libxl_cpupoolid_to_name(ctx, poolid)) {
+        !libxl_cpupoolid_is_valid(ctx, poolid)) {
         fprintf(stderr, "unknown cpupool \'%s\'\n", pool);
         return -ERROR_FAIL;
     }
diff --git a/tools/libxl/xl_sxp.c b/tools/libxl/xl_sxp.c
index 31f9a93..2d33546 100644
--- a/tools/libxl/xl_sxp.c
+++ b/tools/libxl/xl_sxp.c
@@ -37,6 +37,7 @@ void printf_info_sexp(int domid, libxl_domain_config 
*d_config)
 
     libxl_domain_create_info *c_info = &d_config->c_info;
     libxl_domain_build_info *b_info = &d_config->b_info;
+    char *pool;
 
     printf("(domain\n\t(domid %d)\n", domid);
     printf("\t(create_info)\n");
@@ -54,8 +55,10 @@ void printf_info_sexp(int domid, libxl_domain_config 
*d_config)
     } else {
         printf("\t(uuid <unknown>)\n");
     }
-
-    printf("\t(cpupool %s)\n", libxl_cpupoolid_to_name(ctx, c_info->poolid));
+    pool = libxl_cpupoolid_to_name(ctx, c_info->poolid);
+    if (pool)
+        printf("\t(cpupool %s)\n", pool);
+    free(pool);
     if (c_info->xsdata)
         printf("\t(xsdata contains data)\n");
     else
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.2

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.