Skip to contentSkip to conversation

add missing libxl__free_all() calls

PATCH In review Juergen Gross 3 participants 3 messages Dec 9, 2010 – Dec 13, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 add missing libxl__free_all() calls

In various libxl functions libxl__free_all() was missing before return

Signed-off-by [email protected]
3 files changed, 39 insertions(+), 12 deletions(-)
tools/libxl/libxl.c     |   34 ++++++++++++++++++++++++++--------
tools/libxl/libxl_dom.c |   13 ++++++++++---
tools/libxl/libxl_pci.c |    4 +++-

# HG changeset patch
# User Juergen Gross <[email protected]> # Date 1291902656 -3600
# Node ID 9ada9b410270be89e4e9add0e5940c4cd1315ec8 # Parent ee1409ba09719d310bd88885ee860ad0bf73366f add missing libxl__free_all() calls

In various libxl functions libxl__free_all() was missing before return

Signed-off-by [email protected]
tools/libxl/libxl.c +26 -8
diff -r ee1409ba0971 -r 9ada9b410270 tools/libxl/libxl.c
@@ -514,7 +514,10 @@ int libxl_domain_preserve(libxl_ctx *ctx
 
     xs_write(ctx->xsh, t, libxl__sprintf(&gc, "%s/vm", dom_path), vm_path, strlen(vm_path));
     rc = libxl_domain_rename(ctx, domid, info->name, preserved_name, t);
-    if (rc) return rc;
+    if (rc) {
+        libxl__free_all(&gc);
+        return rc;
+    }
 
     xs_write(ctx->xsh, t, libxl__sprintf(&gc, "%s/uuid", vm_path), uuid_string, strlen(uuid_string));
 
@@ -756,17 +759,20 @@ int libxl_domain_shutdown(libxl_ctx *ctx
         ret = xc_get_hvm_param(ctx->xch, domid, HVM_PARAM_ACPI_S_STATE, &acpi_s_state);
         if (ret<0) {
             LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting ACPI S-state");
+            libxl__free_all(&gc);
             return ERROR_FAIL;
         }
         ret = xc_get_hvm_param(ctx->xch, domid, HVM_PARAM_CALLBACK_IRQ, &pvdriver);
         if (ret<0) {
             LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting HVM callback IRQ");
+            libxl__free_all(&gc);
             return ERROR_FAIL;
         }
         if (!pvdriver || acpi_s_state != 0) {
             ret = xc_domain_shutdown(ctx->xch, domid, req);
             if (ret<0) {
                 LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "unpausing domain");
+                libxl__free_all(&gc);
                 return ERROR_FAIL;
             }
        }
@@ -3714,13 +3720,16 @@ int libxl_create_cpupool(libxl_ctx *ctx,
     char *uuid_string;
 
     uuid_string = libxl__uuid2string(&gc, *uuid);
-    if (!uuid_string)
-        return ERROR_NOMEM;
+    if (!uuid_string) {
+        libxl__free_all(&gc);
+        return ERROR_NOMEM;
+    }
 
     rc = xc_cpupool_create(ctx->xch, poolid, schedid);
     if (rc) {
         LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
            "Could not create cpupool");
+        libxl__free_all(&gc);
         return ERROR_FAIL;
     }
 
@@ -3731,6 +3740,7 @@ int libxl_create_cpupool(libxl_ctx *ctx,
                 LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
                     "Error moving cpu to cpupool");
                 libxl_destroy_cpupool(ctx, *poolid);
+                libxl__free_all(&gc);
                 return ERROR_FAIL;
             }
         }
@@ -3746,8 +3756,10 @@ int libxl_create_cpupool(libxl_ctx *ctx,
                         libxl__sprintf(&gc, "/local/pool/%d/name", *poolid),
                         "%s", name);
 
-        if (xs_transaction_end(ctx->xsh, t, 0) || (errno != EAGAIN))
+        if (xs_transaction_end(ctx->xsh, t, 0) || (errno != EAGAIN)) {
+            libxl__free_all(&gc);
             return 0;
+        }
     }
 }
 
@@ -3760,8 +3772,10 @@ int libxl_destroy_cpupool(libxl_ctx *ctx
     libxl_cpumap cpumap;
 
     info = xc_cpupool_getinfo(ctx->xch, poolid);
-    if (info == NULL)
-        return ERROR_NOMEM;
+    if (info == NULL) {
+        libxl__free_all(&gc);
+        return ERROR_NOMEM;
+    }
 
     rc = ERROR_INVAL;
     if ((info->cpupool_id != poolid) || (info->n_dom))
@@ -3805,6 +3819,7 @@ out1:
     libxl_cpumap_destroy(&cpumap);
 out:
     xc_cpupool_infofree(ctx->xch, info);
+    libxl__free_all(&gc);
 
     return rc;
 }
@@ -3963,6 +3978,7 @@ int libxl_cpupool_movedomain(libxl_ctx *
 
     dom_path = libxl__xs_get_dompath(&gc, domid);
     if (!dom_path) {
+        libxl__free_all(&gc);
         return ERROR_FAIL;
     }
 
@@ -3970,6 +3986,7 @@ int libxl_cpupool_movedomain(libxl_ctx *
     if (rc) {
         LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
             "Error moving domain to cpupool");
+        libxl__free_all(&gc);
         return ERROR_FAIL;
     }
 
@@ -3988,5 +4005,6 @@ int libxl_cpupool_movedomain(libxl_ctx *
             break;
     }
 
-    return 0;
-}
+    libxl__free_all(&gc);
+    return 0;
+}
tools/libxl/libxl_dom.c +10 -3
diff -r ee1409ba0971 -r 9ada9b410270 tools/libxl/libxl_dom.c
@@ -121,8 +121,10 @@ int libxl__build_post(libxl_ctx *ctx, ui
     }
 
     dom_path = libxl__xs_get_dompath(&gc, domid);
-    if (!dom_path)
+    if (!dom_path) {
+        libxl__free_all(&gc);
         return ERROR_FAIL;
+    }
 
     vm_path = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, "%s/vm", dom_path), NULL);
 retry_transaction:
@@ -469,6 +471,7 @@ int libxl__domain_save_device_model(libx
     if (stat(filename, &st) < 0)
     {
         LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Unable to stat qemu save file\n");
+        libxl__free_all(&gc);
         return ERROR_FAIL;
     }
 
@@ -477,13 +480,17 @@ int libxl__domain_save_device_model(libx
 
     c = libxl_write_exactly(ctx, fd, QEMU_SIGNATURE, strlen(QEMU_SIGNATURE),
                             "saved-state file", "qemu signature");
-    if (c)
+    if (c) {
+        libxl__free_all(&gc);
         return c;
+    }
 
     c = libxl_write_exactly(ctx, fd, &qemu_state_len, sizeof(qemu_state_len),
                             "saved-state file", "saved-state length");
-    if (c)
+    if (c) {
+        libxl__free_all(&gc);
         return c;
+    }
 
     fd2 = open(filename, O_RDONLY);
     while ((c = read(fd2, buf, sizeof(buf))) != 0) {
tools/libxl/libxl_pci.c +3 -1
diff -r ee1409ba0971 -r 9ada9b410270 tools/libxl/libxl_pci.c
@@ -525,8 +525,10 @@ int libxl_device_pci_list_assignable(lib
     *list = NULL;
 
     rc = get_all_assigned_devices(&gc, &assigned, &num_assigned);
-    if ( rc )
+    if ( rc ) {
+        libxl__free_all(&gc);
         return rc;
+    }
 
     dir = opendir(SYSFS_PCIBACK_DRIVER);
     if ( NULL == dir ) {

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

tools/libxl/libxl.c int libxl_destroy_cpupool(libxl_ctx *ctx · line 3778

Quoted 10 lines · Juergen Gross
tools/libxl/libxl.c +4 -2
@@ -3760,8 +3772,10 @@ int libxl_destroy_cpupool(libxl_ctx *ctx
     libxl_cpumap cpumap;
 
     info = xc_cpupool_getinfo(ctx->xch, poolid);
-    if (info == NULL)
-        return ERROR_NOMEM;
+    if (info == NULL) {
+        libxl__free_all(&gc);
+        return ERROR_NOMEM;
+    }

This one is un-necessary but harmless. The INIT_GC macro just zeros the structure and allocates nothing. It might not be wise to rely on programmer knowing that about the implementation in the long run...

Quoted 11 lines
tools/libxl/libxl.c +1 -0
     rc = ERROR_INVAL;
     if ((info->cpupool_id != poolid) || (info->n_dom))
@@ -3805,6 +3819,7 @@ out1:
     libxl_cpumap_destroy(&cpumap);
 out:
     xc_cpupool_infofree(ctx->xch, info);
+    libxl__free_all(&gc);
 
     return rc;
 }

tools/libxl/libxl.c int libxl_cpupool_movedomain(libxl_ctx * · line 3983

Quoted 6 lines
tools/libxl/libxl.c +1 -0
@@ -3963,6 +3978,7 @@ int libxl_cpupool_movedomain(libxl_ctx *
 
     dom_path = libxl__xs_get_dompath(&gc, domid);
     if (!dom_path) {
+        libxl__free_all(&gc);
         return ERROR_FAIL;
     }

Same again.

All the others are correct, most of them obviously so just from the diff context, making them good catches. Nice work.

Gianni

#2 lore raw
Quoted 4 lines · Gianni Tedesco
Quoted 3 lines · Juergen Gross
tools/libxl/libxl.c +0 -0
@@ -3760,8 +3772,10 @@ int libxl_destroy_cpupool(libxl_ctx *ctx
     libxl_cpumap cpumap;
 
Quoted 12 lines

tools/libxl/libxl.c int libxl_destroy_cpupool(libxl_ctx *ctx · line 3778

Quoted 7 lines
tools/libxl/libxl.c +4 -2
     info = xc_cpupool_getinfo(ctx->xch, poolid);
-    if (info == NULL)
-        return ERROR_NOMEM;
+    if (info == NULL) {
+        libxl__free_all(&gc);
+        return ERROR_NOMEM;
+    }

This one is un-necessary but harmless. The INIT_GC macro just zeros the structure and allocates nothing. It might not be wise to rely on programmer knowing that about the implementation in the long run...

I actually think that is a good idea to always call libxl__free_all before exiting.
libxl__free_all should guarantee to do the right thing no matter if something has been allocated or not, so I am going to apply the patch as is.
Thanks!

Stefano