qemuMonitorGetMemoryDeviceInfo: Assign hash table only on success

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Tim Wiederhake 2021-07-05 16:01:00 +02:00
parent 78f47cba9b
commit 927c9969b9

View File

@ -4214,6 +4214,7 @@ int
qemuMonitorGetMemoryDeviceInfo(qemuMonitor *mon, qemuMonitorGetMemoryDeviceInfo(qemuMonitor *mon,
GHashTable **info) GHashTable **info)
{ {
GHashTable *hash;
int ret; int ret;
VIR_DEBUG("info=%p", info); VIR_DEBUG("info=%p", info);
@ -4222,14 +4223,13 @@ qemuMonitorGetMemoryDeviceInfo(qemuMonitor *mon,
QEMU_CHECK_MONITOR(mon); QEMU_CHECK_MONITOR(mon);
if (!(*info = virHashNew(g_free))) if (!(hash = virHashNew(g_free)))
return -1; return -1;
if ((ret = qemuMonitorJSONGetMemoryDeviceInfo(mon, *info)) < 0) { if ((ret = qemuMonitorJSONGetMemoryDeviceInfo(mon, hash)) >= 0)
virHashFree(*info); *info = g_steal_pointer(&hash);
*info = NULL;
}
virHashFree(hash);
return ret; return ret;
} }