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(a)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