WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 1 of 3] libxl: do not leak uuid strings used internal

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 1 of 3] libxl: do not leak uuid strings used internally
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Fri, 13 Aug 2010 15:30:08 +0100
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Delivery-date: Fri, 13 Aug 2010 07:33:20 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1281709807@xxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1281709508 -3600
# Node ID 72d92574410da1d388dd33e5fe10e955fd1a93ec
# Parent  adefd8ef59992b04b6d7da35f81ff6d7cc48a6a6
libxl: do not leak uuid strings used internally

Use string_of_uuid (which adds the string to the gc context) instead
of libxl_uuid_to_string (which adds the string to the context and then
strdups it!).

Fixes this valgrind warning:
==10005== 37 bytes in 1 blocks are definitely lost in loss record 1 of 1
==10005==    at 0x4022F0A: malloc (vg_replace_malloc.c:236)
==10005==    by 0x411A22F: strdup (in /lib/i686/cmov/libc-2.7.so)
==10005==    by 0x4047930: libxl_uuid2string (libxl_dom.c:454)
==10005==    by 0x404185A: libxl_domain_make (libxl.c:121)
==10005==    by 0x8056F5B: create_domain (xl_cmdimpl.c:1387)
==10005==    by 0x8058216: main_create (xl_cmdimpl.c:3171)
==10005==    by 0x804B5AB: main (xl.c:76)

libxl_domain_preserve and libxl_set_memory_target suffer the same
problem by inspection only.

Also since string_of_uuid now takes a gc not a ctx rename the variable
to be less confusing.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>

diff -r adefd8ef5999 -r 72d92574410d tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Fri Aug 13 14:47:53 2010 +0100
+++ b/tools/libxl/libxl.c       Fri Aug 13 15:25:08 2010 +0100
@@ -118,7 +118,7 @@ int libxl_domain_make(libxl_ctx *ctx, li
     xs_transaction_t t;
     xen_domain_handle_t handle;
 
-    uuid_string = libxl_uuid2string(ctx, info->uuid);
+    uuid_string = string_of_uuid(&gc, info->uuid);
     if (!uuid_string) {
         libxl_free_all(&gc);
         return ERROR_NOMEM;
@@ -481,7 +481,7 @@ int libxl_domain_preserve(libxl_ctx *ctx
         return ERROR_NOMEM;
     }
 
-    uuid_string = libxl_uuid2string(ctx, new_uuid);
+    uuid_string = string_of_uuid(&gc, new_uuid);
     if (!uuid_string) {
         libxl_free_all(&gc);
         return ERROR_NOMEM;
@@ -2813,7 +2813,7 @@ int libxl_set_memory_target(libxl_ctx *c
     if (rc != 1 || info.domain != domid)
         goto out;
     xcinfo2xlinfo(&info, &ptr);
-    uuid = libxl_uuid2string(ctx, ptr.uuid);
+    uuid = string_of_uuid(&gc, ptr.uuid);
     libxl_xs_write(&gc, XBT_NULL, libxl_sprintf(&gc, "/vm/%s/memory", uuid), 
"%"PRIu32, target_memkb / 1024);
 
     if (enforce || !domid)
diff -r adefd8ef5999 -r 72d92574410d tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h      Fri Aug 13 14:47:53 2010 +0100
+++ b/tools/libxl/libxl_internal.h      Fri Aug 13 15:25:08 2010 +0100
@@ -107,8 +107,8 @@ typedef struct {
 #define PRINTF_ATTRIBUTE(x, y) __attribute__((format(printf, x, y)))
 
 #define UUID_FMT 
"%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
-#define string_of_uuid(ctx, u) \
-    libxl_sprintf(ctx, UUID_FMT, \
+#define string_of_uuid(gc, u) \
+    libxl_sprintf(gc, UUID_FMT, \
                 (u)[0], (u)[1], (u)[2], (u)[3], (u)[4], (u)[5], (u)[6], 
(u)[7], \
                 (u)[8], (u)[9], (u)[10], (u)[11], (u)[12], (u)[13], (u)[14], 
(u)[15])
 

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel