[PATCH] qemuDomainSaveInternal: fix memoryleak of virDomainDef

From: Zheng Chuan <zhengchuan@huawei.com> virDomainDefPtr 'def' is forgot to free after qemuDomainDefFormatLive(), fix it. Signed-off-by: Zheng Chuan <zhengchuan@huawei.com> --- src/qemu/qemu_driver.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 53980d4..b145318 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3369,6 +3369,7 @@ qemuDomainSaveInternal(virQEMUDriverPtr driver, goto endjob; } xml = qemuDomainDefFormatLive(driver, priv->qemuCaps, def, NULL, true, true); + virDomainDefFree(def); } else { xml = qemuDomainDefFormatLive(driver, priv->qemuCaps, vm->def, priv->origCPU, true, true); -- 1.8.3.1

On 7/28/20 9:56 PM, Chuan Zheng wrote:
From: Zheng Chuan <zhengchuan@huawei.com>
virDomainDefPtr 'def' is forgot to free after qemuDomainDefFormatLive(), fix it.
Signed-off-by: Zheng Chuan <zhengchuan@huawei.com> --- src/qemu/qemu_driver.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 53980d4..b145318 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3369,6 +3369,7 @@ qemuDomainSaveInternal(virQEMUDriverPtr driver, goto endjob; } xml = qemuDomainDefFormatLive(driver, priv->qemuCaps, def, NULL, true, true); + virDomainDefFree(def); } else { xml = qemuDomainDefFormatLive(driver, priv->qemuCaps, vm->def, priv->origCPU, true, true);
Instead you could use g_autoptr when defining def: g_autoptr(virDomainDef) def = NULL; (and then remove the existing call to virDomainDefFree() that's a few lines down)(and get rid of the { } around the now single line "goto endjob;" that remains). That way def is just always freed when leaving the scope of the "if (xmlin) { }"
participants (2)
-
Chuan Zheng
-
Laine Stump