[PATCH v2] qemuDomainSaveInternal: fix memoryleak of virDomainDef

Chuan Zheng zhengchuan at huawei.com
Wed Jul 29 03:42:49 UTC 2020


From: Zheng Chuan <zhengchuan at huawei.com>

virDomainDefPtr 'def' is forgot to free after qemuDomainDefFormatLive(), fix it.

Signed-off-by: Zheng Chuan <zhengchuan at huawei.com>
---
 src/qemu/qemu_driver.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 53980d4..2dafe7c 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -3356,18 +3356,15 @@ 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,
                                             VIR_DOMAIN_DEF_PARSE_INACTIVE |
-                                            VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE))) {
+                                            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,
-- 
1.8.3.1




More information about the libvir-list mailing list