]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuMonitorGetMemoryDeviceInfo: Assign hash table only on success
authorTim Wiederhake <twiederh@redhat.com>
Mon, 5 Jul 2021 14:01:00 +0000 (16:01 +0200)
committerTim Wiederhake <twiederh@redhat.com>
Wed, 14 Jul 2021 13:36:27 +0000 (15:36 +0200)
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/qemu/qemu_monitor.c

index a2df1a6ec385db32a9456bf949e658b72d032238..9b1a3ec3eb72f4279948834db930266021008aa4 100644 (file)
@@ -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;
 }