qemuMonitorJSONBlockInfoAdd: Refactor hash table addition

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

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2021-10-13 15:25:15 +02:00
parent 04a248eb01
commit a1ef0b129a

View File

@ -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;
tmp->nodename = g_strdup(info->nodename);
if (info->nodename)
tmp->nodename = g_strdup(info->nodename);
g_hash_table_insert(table, g_strdup(entryname), tmp);
if (virHashAddEntry(table, entryname, tmp) < 0)
goto cleanup;
tmp = NULL;
ret = 0;
cleanup:
if (tmp)
VIR_FREE(tmp->nodename);
VIR_FREE(tmp);
return ret;
return 0;
}