mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 20:45:18 +00:00
qemuMonitorJSONGetStringArray: 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
ea0b164367
commit
1a468c01a8
@ -7201,12 +7201,12 @@ qemuMonitorJSONBlockExportAdd(qemuMonitor *mon,
|
|||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuMonitorJSONGetStringArray(qemuMonitor *mon, const char *qmpCmd,
|
qemuMonitorJSONGetStringArray(qemuMonitor *mon,
|
||||||
|
const char *qmpCmd,
|
||||||
char ***array)
|
char ***array)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
g_autoptr(virJSONValue) cmd = NULL;
|
||||||
virJSONValue *cmd;
|
g_autoptr(virJSONValue) reply = NULL;
|
||||||
virJSONValue *reply = NULL;
|
|
||||||
|
|
||||||
*array = NULL;
|
*array = NULL;
|
||||||
|
|
||||||
@ -7214,25 +7214,18 @@ qemuMonitorJSONGetStringArray(qemuMonitor *mon, const char *qmpCmd,
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
|
if (qemuMonitorJSONHasError(reply, "CommandNotFound"))
|
||||||
ret = 0;
|
return 0;
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
|
if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (!(*array = virJSONValueObjectGetStringArray(reply, "return")))
|
if (!(*array = virJSONValueObjectGetStringArray(reply, "return")))
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
ret = g_strv_length(*array);
|
return g_strv_length(*array);
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virJSONValueFree(cmd);
|
|
||||||
virJSONValueFree(reply);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int qemuMonitorJSONGetTPMModels(qemuMonitor *mon,
|
int qemuMonitorJSONGetTPMModels(qemuMonitor *mon,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user