[libvirt] [PATCH v2] snapshot:Fix double memory free to the qemuImgBinary field in qemu_driver struct

Guannan Ren gren at redhat.com
Sun Sep 11 05:43:35 UTC 2011


     *src/qemu/qemu_driver.c: In qemuDomainSnapshotForEachQcow()
          it free up the memory of qemu_driver->qemuImgBinary in the
          cleanup tag which leads to the garbage value of qemuImgBinary
          in qemu_driver struct and libvirtd crash when running
          "virsh snapshot-create" command at second time.
---
 src/qemu/qemu_driver.c |   13 ++++---------
 1 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index b94d1c4..d5a2bc0 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1681,14 +1681,13 @@ qemuDomainSnapshotForEachQcow2(struct qemud_driver *driver,
                                bool try_all)
 {
     const char *qemuimgarg[] = { NULL, "snapshot", NULL, NULL, NULL, NULL };
-    int ret = -1;
     int i;
     bool skipped = false;
 
     qemuimgarg[0] = qemuFindQemuImgBinary(driver);
     if (qemuimgarg[0] == NULL) {
         /* qemuFindQemuImgBinary set the error */
-        goto cleanup;
+        return -1;
     }
 
     qemuimgarg[2] = op;
@@ -1715,7 +1714,7 @@ qemuDomainSnapshotForEachQcow2(struct qemud_driver *driver,
                                 _("Disk device '%s' does not support"
                                   " snapshotting"),
                                 vm->def->disks[i]->info.alias);
-                goto cleanup;
+                return -1;
             }
 
             qemuimgarg[4] = vm->def->disks[i]->src;
@@ -1727,16 +1726,12 @@ qemuDomainSnapshotForEachQcow2(struct qemud_driver *driver,
                     skipped = true;
                     continue;
                 }
-                goto cleanup;
+                return -1;
             }
         }
     }
 
-    ret = skipped ? 1 : 0;
-
-cleanup:
-    VIR_FREE(qemuimgarg[0]);
-    return ret;
+    return skipped ? 1 : 0;
 }
 
 /* Discard one snapshot (or its metadata), without reparenting any children.  */
-- 
1.7.1




More information about the libvir-list mailing list