[libvirt] [PATCH] qemu: Fix memory leak in qemuDomainUpdateMemoryDeviceInfo

Yi Wang posted 1 patch 6 years, 10 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/1495678816-44191-1-git-send-email-wang.yi59@zte.com.cn
src/qemu/qemu_domain.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
[libvirt] [PATCH] qemu: Fix memory leak in qemuDomainUpdateMemoryDeviceInfo
Posted by Yi Wang 6 years, 10 months ago
The @meminfo allocated in qemuMonitorGetMemoryDeviceInfo may be lost when
exit monitor failed. Luckily we can free it according to rc.

Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
---
 src/qemu/qemu_domain.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index c8dc748..c34ec5a 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -5767,8 +5767,11 @@ qemuDomainUpdateMemoryDeviceInfo(virQEMUDriverPtr driver,
 
     rc = qemuMonitorGetMemoryDeviceInfo(priv->mon, &meminfo);
 
-    if (qemuDomainObjExitMonitor(driver, vm) < 0)
+    if (qemuDomainObjExitMonitor(driver, vm) < 0) {
+        if (0 == rc)
+            virHashFree(meminfo);
         return -1;
+    }
 
     /* if qemu doesn't support the info request, just carry on */
     if (rc == -2)
-- 
1.8.3.1


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu: Fix memory leak in qemuDomainUpdateMemoryDeviceInfo
Posted by Michal Privoznik 6 years, 11 months ago
On 05/25/2017 04:20 AM, Yi Wang wrote:
> The @meminfo allocated in qemuMonitorGetMemoryDeviceInfo may be lost when
> exit monitor failed. Luckily we can free it according to rc.
> 
> Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
> ---
>  src/qemu/qemu_domain.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
> index c8dc748..c34ec5a 100644
> --- a/src/qemu/qemu_domain.c
> +++ b/src/qemu/qemu_domain.c
> @@ -5767,8 +5767,11 @@ qemuDomainUpdateMemoryDeviceInfo(virQEMUDriverPtr driver,
>  
>      rc = qemuMonitorGetMemoryDeviceInfo(priv->mon, &meminfo);
>  
> -    if (qemuDomainObjExitMonitor(driver, vm) < 0)
> +    if (qemuDomainObjExitMonitor(driver, vm) < 0) {
> +        if (0 == rc)

We don't use this style in libvirt. Moreover, there's no real need for
the check as virHashFree() accepts NULL happily.

> +            virHashFree(meminfo);
>          return -1;
> +    }
>  
>      /* if qemu doesn't support the info request, just carry on */
>      if (rc == -2)
> 

I've fixed that, ACKed and pushed.

Michal

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