[libvirt PATCH 08/10] qemuMonitorGetMemoryDeviceInfo: Assign hash table only on success

Tim Wiederhake twiederh at redhat.com
Fri Jul 9 08:27:37 UTC 2021


Signed-off-by: Tim Wiederhake <twiederh at redhat.com>
---
 src/qemu/qemu_monitor.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 8f35b4240f..8646efe9c4 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -4238,6 +4238,7 @@ int
 qemuMonitorGetMemoryDeviceInfo(qemuMonitor *mon,
                                GHashTable **info)
 {
+    GHashTable *hash;
     int ret;
 
     VIR_DEBUG("info=%p", info);
@@ -4246,14 +4247,14 @@ 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) {
+        virHashFree(hash);
     }
 
+    *info = hash;
     return ret;
 }
 
-- 
2.31.1




More information about the libvir-list mailing list