]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Fix memory leak while scanning snapshots
authorPhilipp Hahn <hahn@univention.de>
Tue, 9 Aug 2011 13:47:57 +0000 (15:47 +0200)
committerEric Blake <eblake@redhat.com>
Tue, 9 Aug 2011 16:13:33 +0000 (10:13 -0600)
If a snapshot with the name already exists, virDomainSnapshotAssignDef()
just returns NULL, in which case the snapshot definition is leaked.
Currently this leak is not a big problem, since qemuDomainSnapshotLoad()
is only called once during initial startup of libvirtd.

Signed-off-by: Philipp Hahn <hahn@univention.de>
src/qemu/qemu_driver.c

index ce19be78e9259b23e3c701c2c0beccd22125b8b5..b8150468f35081d62eed8ef04484851f491b36c9 100644 (file)
@@ -293,6 +293,7 @@ static void qemuDomainSnapshotLoad(void *payload,
     int ret;
     char *fullpath;
     virDomainSnapshotDefPtr def = NULL;
+    virDomainSnapshotObjPtr snap = NULL;
     char ebuf[1024];
 
     virDomainObjLock(vm);
@@ -344,7 +345,10 @@ static void qemuDomainSnapshotLoad(void *payload,
             continue;
         }
 
-        virDomainSnapshotAssignDef(&vm->snapshots, def);
+        snap = virDomainSnapshotAssignDef(&vm->snapshots, def);
+        if (snap == NULL) {
+            virDomainSnapshotDefFree(def);
+        }
 
         VIR_FREE(fullpath);
         VIR_FREE(xmlStr);