[libvirt PATCH] qemu: Avoid memory leak in qemuMonitorJSONExtractQueryStatsSchema

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux