mirror of https://gitee.com/openkylin/libvirt.git
qemuMonitorJSONGetObjectTypes: Refactor cleanup
Use automatic memory clearing to simplify the control flow. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
1a468c01a8
commit
ed4c75c4da
|
@ -6293,14 +6293,14 @@ int qemuMonitorJSONGetKVMState(qemuMonitor *mon,
|
|||
}
|
||||
|
||||
|
||||
int qemuMonitorJSONGetObjectTypes(qemuMonitor *mon,
|
||||
char ***types)
|
||||
int
|
||||
qemuMonitorJSONGetObjectTypes(qemuMonitor *mon,
|
||||
char ***types)
|
||||
{
|
||||
int ret = -1;
|
||||
virJSONValue *cmd;
|
||||
virJSONValue *reply = NULL;
|
||||
g_autoptr(virJSONValue) cmd = NULL;
|
||||
g_autoptr(virJSONValue) reply = NULL;
|
||||
virJSONValue *data;
|
||||
char **typelist = NULL;
|
||||
g_auto(GStrv) typelist = NULL;
|
||||
size_t n = 0;
|
||||
size_t i;
|
||||
|
||||
|
@ -6310,10 +6310,10 @@ int qemuMonitorJSONGetObjectTypes(qemuMonitor *mon,
|
|||
return -1;
|
||||
|
||||
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
data = virJSONValueObjectGetArray(reply, "return");
|
||||
n = virJSONValueArraySize(data);
|
||||
|
@ -6328,20 +6328,14 @@ int qemuMonitorJSONGetObjectTypes(qemuMonitor *mon,
|
|||
if (!(tmp = virJSONValueObjectGetString(child, "name"))) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("qom-list-types reply data was missing 'name'"));
|
||||
goto cleanup;
|
||||
return -1;
|
||||
}
|
||||
|
||||
typelist[i] = g_strdup(tmp);
|
||||
}
|
||||
|
||||
ret = n;
|
||||
*types = g_steal_pointer(&typelist);
|
||||
|
||||
cleanup:
|
||||
g_strfreev(typelist);
|
||||
virJSONValueFree(cmd);
|
||||
virJSONValueFree(reply);
|
||||
return ret;
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue