Skip to contentSkip to conversation

libxl: convert malloc() to libxl__zalloc(NULL, ...)

PATCH In review Dario Faggioli 2 participants 2 messages Jun 6, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxl: convert malloc() to libxl__zalloc(NULL, ...)

And ditch the error handling in libxl_get_cpu_topology()

tools/libxl/libxl.c +1 -6
@@ -3116,12 +3116,7 @@ libxl_cputopology *libxl_get_cpu_topolog
     if (tinfo.max_cpu_index < max_cpus - 1)
         max_cpus = tinfo.max_cpu_index + 1;
 
-    ret = malloc(sizeof(libxl_cputopology) * max_cpus);
-    if (ret == NULL) {
-        LIBXL__LOG_ERRNOVAL(ctx, XTL_ERROR, ENOMEM,
-                            "Unable to allocate return value");
-        goto fail;
-    }
+    ret = libxl__zalloc(NULL, sizeof(libxl_cputopology) * max_cpus);
 
     for (i = 0; i < max_cpus; i++) {
 #define V(map, i) (map[i] == INVALID_TOPOLOGY_ID) ? \
#1 lore raw
Quoted 3 lines · Dario Faggioli

And ditch the error handling in libxl_get_cpu_topology()

Could have used libxl__calloc but I've applied this version.

I added "#define NOGC NULL" and used it instead of NULL, this will mean that when we come to apply <[email protected]> we stand less chance of missing an existing NULL introduced in the interim. Hope that's ok.

Ian.

Quoted 18 lines
tools/libxl/libxl.c +1 -6
@@ -3116,12 +3116,7 @@ libxl_cputopology *libxl_get_cpu_topolog
     if (tinfo.max_cpu_index < max_cpus - 1)
         max_cpus = tinfo.max_cpu_index + 1;
 
-    ret = malloc(sizeof(libxl_cputopology) * max_cpus);
-    if (ret == NULL) {
-        LIBXL__LOG_ERRNOVAL(ctx, XTL_ERROR, ENOMEM,
-                            "Unable to allocate return value");
-        goto fail;
-    }
+    ret = libxl__zalloc(NULL, sizeof(libxl_cputopology) * max_cpus);
 
     for (i = 0; i < max_cpus; i++) {
 #define V(map, i) (map[i] == INVALID_TOPOLOGY_ID) ? \