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

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

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

VGhhbmsgeW91IE1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