[libvirt] [PATCH] qemuDomainSnapshotCreateXML: Don't leak parsed snapshot definition

Michal Privoznik posted 1 patch 4 years, 11 months ago
Test syntax-check passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/208bb6de6d0582614c9e605215f136687abab1d3.1557841837.git.mprivozn@redhat.com
src/qemu/qemu_driver.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[libvirt] [PATCH] qemuDomainSnapshotCreateXML: Don't leak parsed snapshot definition
Posted by Michal Privoznik 4 years, 11 months ago
This function gets snapshot XML (provided by used) as an
argument. It parses it into a local variable @def and then sets
some more members (e.g. it creates a copy of live domain XML).
Then it proceeds to checking if snapshot XML is valid (e.g. it
contains as many disks as currently in the domain). If this fails
then the control jumps to endjob label and subsequently return
from the function. This is where AUTOFREE function for @def is
ran. Well, because the code says to run plain VIR_FREE() we leak
some memory because @def is actually an object and therefore
it should have been declared as AUTOUNREF.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_driver.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index f01282a037..0a425b82e5 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -15563,7 +15563,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
     virCapsPtr caps = NULL;
     qemuDomainObjPrivatePtr priv;
     virDomainSnapshotState state;
-    VIR_AUTOFREE(virDomainSnapshotDefPtr) def = NULL;
+    VIR_AUTOUNREF(virDomainSnapshotDefPtr) def = NULL;
 
     virCheckFlags(VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE |
                   VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT |
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemuDomainSnapshotCreateXML: Don't leak parsed snapshot definition
Posted by Erik Skultety 4 years, 11 months ago
On Tue, May 14, 2019 at 03:52:07PM +0200, Michal Privoznik wrote:
> This function gets snapshot XML (provided by used) as an
> argument. It parses it into a local variable @def and then sets
> some more members (e.g. it creates a copy of live domain XML).
> Then it proceeds to checking if snapshot XML is valid (e.g. it
> contains as many disks as currently in the domain). If this fails
> then the control jumps to endjob label and subsequently return
> from the function. This is where AUTOFREE function for @def is
> ran. Well, because the code says to run plain VIR_FREE() we leak
> some memory because @def is actually an object and therefore
> it should have been declared as AUTOUNREF.
>
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
Reviewed-by: Erik Skultety <eskultet@redhat.com>

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemuDomainSnapshotCreateXML: Don't leak parsed snapshot definition
Posted by Eric Blake 4 years, 11 months ago
On 5/14/19 8:52 AM, Michal Privoznik wrote:
> This function gets snapshot XML (provided by used) as an
> argument. It parses it into a local variable @def and then sets
> some more members (e.g. it creates a copy of live domain XML).
> Then it proceeds to checking if snapshot XML is valid (e.g. it
> contains as many disks as currently in the domain). If this fails
> then the control jumps to endjob label and subsequently return
> from the function. This is where AUTOFREE function for @def is
> ran. Well, because the code says to run plain VIR_FREE() we leak
> some memory because @def is actually an object and therefore
> it should have been declared as AUTOUNREF.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/qemu/qemu_driver.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index f01282a037..0a425b82e5 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -15563,7 +15563,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
>      virCapsPtr caps = NULL;
>      qemuDomainObjPrivatePtr priv;
>      virDomainSnapshotState state;
> -    VIR_AUTOFREE(virDomainSnapshotDefPtr) def = NULL;
> +    VIR_AUTOUNREF(virDomainSnapshotDefPtr) def = NULL;

Typo'd in 57387ff5. Thanks for fixing it for me.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list