From ffa7fab4406617e33e30dd2f5246f6e3923da863 Mon Sep 17 00:00:00 2001 From: Zheng Chuan Date: Wed, 29 Jul 2020 11:42:49 +0800 Subject: [PATCH] qemu: fix memory leak in qemuDomainSaveInternal() Use g_autoptr to free the temporary virDomainDef object created by qemuDomainSaveInternal() when xmlin is non-NULL. Leak was added in commit 0ea479f8f6, first appearing in libvirt 0.9.4 in August 2011. Signed-off-by: Zheng Chuan Reviewed-by: Laine Stump --- src/qemu/qemu_driver.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 53980d4d78..0ad6359102 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3356,7 +3356,7 @@ qemuDomainSaveInternal(virQEMUDriverPtr driver, * is NULL or whether it was the live xml of the domain moments * before. */ if (xmlin) { - virDomainDefPtr def = NULL; + g_autoptr(virDomainDef) def = NULL; if (!(def = virDomainDefParseString(xmlin, driver->xmlopt, priv->qemuCaps, @@ -3364,10 +3364,8 @@ qemuDomainSaveInternal(virQEMUDriverPtr driver, VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE))) { goto endjob; } - if (!qemuDomainCheckABIStability(driver, vm, def)) { - virDomainDefFree(def); + if (!qemuDomainCheckABIStability(driver, vm, def)) goto endjob; - } xml = qemuDomainDefFormatLive(driver, priv->qemuCaps, def, NULL, true, true); } else { xml = qemuDomainDefFormatLive(driver, priv->qemuCaps, vm->def,