[PATCH 2/7] qemuMonitorJSONBlockInfoAdd: Refactor hash table addition

Peter Krempa pkrempa at redhat.com
Fri Oct 29 13:14:17 UTC 2021


Open code virHashAddEntry so that the error code path can be avoided.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 src/qemu/qemu_monitor_json.c | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 19af6219aa..962876b43a 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -2220,27 +2220,21 @@ qemuMonitorJSONBlockInfoAdd(GHashTable *table,
                             const char *entryname)
 {
     struct qemuDomainDiskInfo *tmp = NULL;
-    int ret = -1;
+
+    if (g_hash_table_contains(table, entryname)) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Duplicate block info for '%s'"), entryname);
+        return -1;
+    }

     tmp = g_new0(struct qemuDomainDiskInfo, 1);

     *tmp = *info;
-    tmp->nodename = NULL;
-
-    if (info->nodename)
-        tmp->nodename = g_strdup(info->nodename);
+    tmp->nodename = g_strdup(info->nodename);

-    if (virHashAddEntry(table, entryname, tmp) < 0)
-        goto cleanup;
-
-    tmp = NULL;
-    ret = 0;
+    g_hash_table_insert(table, g_strdup(entryname), tmp);

- cleanup:
-    if (tmp)
-        VIR_FREE(tmp->nodename);
-    VIR_FREE(tmp);
-    return ret;
+    return 0;
 }


-- 
2.31.1




More information about the libvir-list mailing list