[PATCH] qemuDomainSaveInternal: fix memoryleak of virDomainDef

Laine Stump laine at redhat.com
Wed Jul 29 02:59:43 UTC 2020


On 7/28/20 9:56 PM, Chuan Zheng wrote:
> 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 | 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) { }"




More information about the libvir-list mailing list