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

Tim Wiederhake posted 10 patches 4 years, 7 months ago
There is a newer version of this series
[libvirt PATCH 08/10] qemuMonitorGetMemoryDeviceInfo: Assign hash table only on success
Posted by Tim Wiederhake 4 years, 7 months ago
Signed-off-by: Tim Wiederhake <twiederh@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