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

[Xen-devel] [PATCH 2 of 4] libxl: do not leak front flexarray on error in libxl_create_pci_backend



# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1294665479 0
# Node ID 3334667c23d1ce06628f768aafc0c683b1c5414e
# Parent  e52d2333fb1616f9d0e30257a788d455fd44e6a2
libxl: do not leak front flexarray on error in libxl_create_pci_backend

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

diff -r e52d2333fb16 -r 3334667c23d1 tools/libxl/libxl_pci.c
--- a/tools/libxl/libxl_pci.c   Mon Jan 10 13:17:59 2011 +0000
+++ b/tools/libxl/libxl_pci.c   Mon Jan 10 13:17:59 2011 +0000
@@ -224,17 +224,19 @@ static int libxl_create_pci_backend(libx
 static int libxl_create_pci_backend(libxl__gc *gc, uint32_t domid, 
libxl_device_pci *pcidev, int num)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
-    flexarray_t *front;
-    flexarray_t *back;
+    flexarray_t *front = NULL;
+    flexarray_t *back = NULL;
     libxl__device device;
-    int i;
+    int ret = ERROR_NOMEM, i;
 
     front = flexarray_make(16, 1);
     if (!front)
-        return ERROR_NOMEM;
+        goto out;
     back = flexarray_make(16, 1);
     if (!back)
-        return ERROR_NOMEM;
+        goto out;
+
+    ret = 0;
 
     LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Creating pci backend");
 
@@ -271,8 +273,11 @@ static int libxl_create_pci_backend(libx
                              libxl__xs_kvs_of_flexarray(gc, back, back->count),
                              libxl__xs_kvs_of_flexarray(gc, front, 
front->count));
 
-    flexarray_free(back);
-    flexarray_free(front);
+out:
+    if (back)
+        flexarray_free(back);
+    if (front)
+        flexarray_free(front);
     return 0;
 }
 

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


 


Rackspace

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