Re: [PATCH] qemuDomainSaveInternal: fix memoryleak of virDomainDef

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 7/28/20 9:56 PM, Chuan Zheng wrote:
From: Zheng Chuan <zhengchuan@xxxxxxxxxx>

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

Signed-off-by: Zheng Chuan <zhengchuan@xxxxxxxxxx>
---
  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) { }"




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux