]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Fix possible memory leak in virsh-domain-monitor.c in cmdDomblklist
authorPavel Hrdina <phrdina@redhat.com>
Mon, 13 Jan 2014 14:42:35 +0000 (15:42 +0100)
committerPavel Hrdina <phrdina@redhat.com>
Thu, 16 Jan 2014 13:47:02 +0000 (14:47 +0100)
In a "for" loop there are created two new strings and they may not
be freed if a "target" string cannot be obtained. We have to free
the two created strings to prevent the memory leak.

This has been found by coverity.

John also pointed out that we should somehow care about the "type"
and "device" and Osier agreed to exit with error message if one of
them is set to NULL.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
tools/virsh-domain-monitor.c

index b29b82a3a74a8e63c892af91f3a1a5548ac92e06..de4afbb33feb4c5a896f5e783041fc37364d0bff 100644 (file)
@@ -545,8 +545,8 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd)
     vshPrint(ctl, "------------------------------------------------\n");
 
     for (i = 0; i < ndisks; i++) {
-        char *type;
-        char *device;
+        char *type = NULL;
+        char *device = NULL;
         char *target;
         char *source;
 
@@ -555,11 +555,19 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd)
         if (details) {
             type = virXPathString("string(./@type)", ctxt);
             device = virXPathString("string(./@device)", ctxt);
+            if (!type || !device) {
+                vshPrint(ctl, "unable to query block list details");
+                VIR_FREE(type);
+                VIR_FREE(device);
+                goto cleanup;
+            }
         }
 
         target = virXPathString("string(./target/@dev)", ctxt);
         if (!target) {
             vshError(ctl, "unable to query block list");
+            VIR_FREE(type);
+            VIR_FREE(device);
             goto cleanup;
         }
         source = virXPathString("string(./source/@file"