[libvirt] [PATCH] 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 <hahn@univention.de> --- src/qemu/qemu_driver.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ce19be7..b815046 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); -- 1.7.1

On 08/09/2011 07:47 AM, Philipp Hahn wrote:
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 | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
ACK and pushed. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
participants (2)
-
Eric Blake
-
Philipp Hahn