[PATCH] qemuDomainGetStatsIOThread: Don't leak array with 0 iothreads

Peter Krempa posted 1 patch 4 years, 1 month ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/635d8daf434227b9fe08650a4bc2142afbe66c96.1582100783.git.pkrempa@redhat.com
src/qemu/qemu_driver.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
[PATCH] qemuDomainGetStatsIOThread: Don't leak array with 0 iothreads
Posted by Peter Krempa 4 years, 1 month ago
qemuMonitorGetIOThreads returns a NULL terminated list even when 0
iothreads are present. The caller didn't perform cleanup if there were 0
iothreads leaking the array.

https://bugzilla.redhat.com/show_bug.cgi?id=1804548

Reported-by: Jing Yan <jiyan@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/qemu/qemu_driver.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index f686b858cf..39e1f044e0 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -21759,8 +21759,12 @@ qemuDomainGetStatsIOThread(virQEMUDriverPtr driver,
     if ((niothreads = qemuDomainGetIOThreadsMon(driver, dom, &iothreads)) < 0)
         return -1;

-    if (niothreads == 0)
-        return 0;
+    /* qemuDomainGetIOThreadsMon returns a NULL-terminated list, so we must free
+     * it even if it returns 0 */
+    if (niothreads == 0) {
+        ret = 0;
+        goto cleanup;
+    }

     if (virTypedParamListAddUInt(params, niothreads, "iothread.count") < 0)
         goto cleanup;
-- 
2.24.1

Re: [PATCH] qemuDomainGetStatsIOThread: Don't leak array with 0 iothreads
Posted by Ján Tomko 4 years, 1 month ago
On Wed, Feb 19, 2020 at 09:26:23AM +0100, Peter Krempa wrote:
>qemuMonitorGetIOThreads returns a NULL terminated list even when 0

NULL-terminated

>iothreads are present. The caller didn't perform cleanup if there were 0
>iothreads leaking the array.
>
>https://bugzilla.redhat.com/show_bug.cgi?id=1804548
>
>Reported-by: Jing Yan <jiyan@redhat.com>
>Signed-off-by: Peter Krempa <pkrempa@redhat.com>

Fixes: d1eac92784573559b6fd56836e33b215c89308e3

>---
> src/qemu/qemu_driver.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano