From: Tim Wiederhake Date: Mon, 5 Jul 2021 14:01:00 +0000 (+0200) Subject: qemuMonitorGetMemoryDeviceInfo: Assign hash table only on success X-Git-Tag: v7.6.0-rc1~200 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=927c9969b9973ed6f40a99d7fc415a3f0f706007;p=thirdparty%2Flibvirt.git qemuMonitorGetMemoryDeviceInfo: Assign hash table only on success Signed-off-by: Tim Wiederhake Reviewed-by: Peter Krempa --- diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index a2df1a6ec3..9b1a3ec3eb 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -4214,6 +4214,7 @@ int qemuMonitorGetMemoryDeviceInfo(qemuMonitor *mon, GHashTable **info) { + GHashTable *hash; int ret; VIR_DEBUG("info=%p", info); @@ -4222,14 +4223,13 @@ qemuMonitorGetMemoryDeviceInfo(qemuMonitor *mon, QEMU_CHECK_MONITOR(mon); - if (!(*info = virHashNew(g_free))) + if (!(hash = virHashNew(g_free))) return -1; - if ((ret = qemuMonitorJSONGetMemoryDeviceInfo(mon, *info)) < 0) { - virHashFree(*info); - *info = NULL; - } + if ((ret = qemuMonitorJSONGetMemoryDeviceInfo(mon, hash)) >= 0) + *info = g_steal_pointer(&hash); + virHashFree(hash); return ret; }