[libvirt PATCH] qemu: Avoid memory leak in qemuMonitorJSONExtractQueryStatsSchema

Jiri Denemark posted 1 patch 1 year, 4 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/273819aeab88b7e7de6c0ddbf7ba2c5005381fa7.1667401010.git.jdenemar@redhat.com
src/qemu/qemu_monitor_json.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
[libvirt PATCH] qemu: Avoid memory leak in qemuMonitorJSONExtractQueryStatsSchema
Posted by Jiri Denemark 1 year, 4 months ago
In a rare case when virHashAddEntry fails we would just leak the
structure we wanted to add to the hash table.

Fixes: e89acdbc3bbada2f3c1a591278bc975ddee2d5a9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/qemu/qemu_monitor_json.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 2bd159bc98..8a3421a6fc 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -8596,7 +8596,7 @@ qemuMonitorJSONExtractQueryStatsSchema(virJSONValue *json)
             virJSONValue *stat = virJSONValueArrayGet(stats, j);
             const char *name = NULL;
             const char *tmp = NULL;
-            qemuMonitorQueryStatsSchemaData *data = NULL;
+            g_autofree qemuMonitorQueryStatsSchemaData *data = NULL;
             int type = -1;
             int unit = -1;
 
@@ -8632,7 +8632,9 @@ qemuMonitorJSONExtractQueryStatsSchema(virJSONValue *json)
                 virJSONValueObjectGetNumberUint(stat, "bucket-size", &data->bucket_size) < 0)
                 data->bucket_size = 0;
 
-            virHashAddEntry(schema, name, data);
+            if (virHashAddEntry(schema, name, data) < 0)
+                return NULL;
+            data = NULL;
         }
     }
 
-- 
2.38.1
Re: [libvirt PATCH] qemu: Avoid memory leak in qemuMonitorJSONExtractQueryStatsSchema
Posted by Ján Tomko 1 year, 4 months ago
On a Wednesday in 2022, Jiri Denemark wrote:
>In a rare case when virHashAddEntry fails we would just leak the
>structure we wanted to add to the hash table.
>
>Fixes: e89acdbc3bbada2f3c1a591278bc975ddee2d5a9
>Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
>---
> src/qemu/qemu_monitor_json.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>

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

Jano