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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 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




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux