From: Philipp Hahn Date: Tue, 9 Aug 2011 13:47:57 +0000 (+0200) Subject: Fix memory leak while scanning snapshots X-Git-Tag: v0.9.5-rc1~271 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=839a5295ef568727b025f9546c1720279f49fe62;p=thirdparty%2Flibvirt.git Fix memory leak while scanning snapshots 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 --- diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ce19be78e9..b8150468f3 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -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);