From: Peter Krempa Date: Wed, 13 Oct 2021 13:25:15 +0000 (+0200) Subject: qemuMonitorJSONBlockInfoAdd: Refactor hash table addition X-Git-Tag: v7.10.0-rc1~257 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a1ef0b129a22e5706716cc0e25511cdeedb6dea0;p=thirdparty%2Flibvirt.git qemuMonitorJSONBlockInfoAdd: Refactor hash table addition Open code virHashAddEntry so that the error code path can be avoided. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- 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; }