]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
xen: Resolve resource leak with 'cpuset'
authorJohn Ferlan <jferlan@redhat.com>
Thu, 10 Jan 2013 17:46:52 +0000 (12:46 -0500)
committerJán Tomko <jtomko@redhat.com>
Tue, 15 Jan 2013 13:50:35 +0000 (14:50 +0100)
Make cpuset local to the while loop and free it once done with it each
time through the loop.  Add a sa_assert() to virBitmapParse() to keep Coverity
from believing there could be a negative return and possible resource leak.

src/util/virbitmap.c
src/xen/xend_internal.c

index e0323742ed9b3b498fae0646bb76e262fb706545..ca82d1be879266cb07bcf3df4619e995523f16d6 100644 (file)
@@ -373,6 +373,7 @@ int virBitmapParse(const char *str,
         }
     }
 
+    sa_assert(ret >= 0);
     return ret;
 
 parse_error:
index 84a25e80c115088bf0bcd5f1ecb7da22be482aa8..959225ccc74fb90a91ed582e479034574777aee5 100644 (file)
@@ -1113,7 +1113,6 @@ sexpr_to_xend_topology(const struct sexpr *root,
 {
     const char *nodeToCpu;
     const char *cur;
-    virBitmapPtr cpuset = NULL;
     int *cpuNums = NULL;
     int cell, cpu, nb_cpus;
     int n = 0;
@@ -1131,6 +1130,7 @@ sexpr_to_xend_topology(const struct sexpr *root,
 
     cur = nodeToCpu;
     while (*cur != 0) {
+        virBitmapPtr cpuset = NULL;
         /*
          * Find the next NUMA cell described in the xend output
          */
@@ -1163,28 +1163,22 @@ sexpr_to_xend_topology(const struct sexpr *root,
             if (used)
                 cpuNums[n++] = cpu;
         }
+        virBitmapFree(cpuset);
 
-        if (virCapabilitiesAddHostNUMACell(caps,
-                                           cell,
-                                           nb_cpus,
-                                           cpuNums) < 0)
+        if (virCapabilitiesAddHostNUMACell(caps, cell, nb_cpus, cpuNums) < 0)
             goto memory_error;
     }
     VIR_FREE(cpuNums);
-    virBitmapFree(cpuset);
     return 0;
 
   parse_error:
     virReportError(VIR_ERR_XEN_CALL, "%s", _("topology syntax error"));
   error:
     VIR_FREE(cpuNums);
-    virBitmapFree(cpuset);
-
     return -1;
 
   memory_error:
     VIR_FREE(cpuNums);
-    virBitmapFree(cpuset);
     virReportOOMError();
     return -1;
 }