mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
testQemuMonitorJSONGetCommands: Refactor cleanup
Use g_auto(GStrv) for clearing the string list and thus remove the 'cleanup' section and 'ret' variable. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
ed4c75c4da
commit
d5578879a8
@ -502,10 +502,8 @@ testQemuMonitorJSONGetCommands(const void *opaque)
|
|||||||
{
|
{
|
||||||
const testGenericData *data = opaque;
|
const testGenericData *data = opaque;
|
||||||
virDomainXMLOption *xmlopt = data->xmlopt;
|
virDomainXMLOption *xmlopt = data->xmlopt;
|
||||||
int ret = -1;
|
g_auto(GStrv) commands = NULL;
|
||||||
char **commands = NULL;
|
|
||||||
int ncommands = 0;
|
int ncommands = 0;
|
||||||
size_t i;
|
|
||||||
g_autoptr(qemuMonitorTest) test = NULL;
|
g_autoptr(qemuMonitorTest) test = NULL;
|
||||||
|
|
||||||
if (!(test = qemuMonitorTestNewSchema(xmlopt, data->schema)))
|
if (!(test = qemuMonitorTestNewSchema(xmlopt, data->schema)))
|
||||||
@ -525,16 +523,16 @@ testQemuMonitorJSONGetCommands(const void *opaque)
|
|||||||
" } "
|
" } "
|
||||||
" ]"
|
" ]"
|
||||||
"}") < 0)
|
"}") < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if ((ncommands = qemuMonitorGetCommands(qemuMonitorTestGetMonitor(test),
|
if ((ncommands = qemuMonitorGetCommands(qemuMonitorTestGetMonitor(test),
|
||||||
&commands)) < 0)
|
&commands)) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (ncommands != 3) {
|
if (ncommands != 3) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
"ncommands %d is not 3", ncommands);
|
"ncommands %d is not 3", ncommands);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CHECK(i, wantname) \
|
#define CHECK(i, wantname) \
|
||||||
@ -543,7 +541,7 @@ testQemuMonitorJSONGetCommands(const void *opaque)
|
|||||||
virReportError(VIR_ERR_INTERNAL_ERROR, \
|
virReportError(VIR_ERR_INTERNAL_ERROR, \
|
||||||
"name %s is not %s", \
|
"name %s is not %s", \
|
||||||
commands[i], (wantname)); \
|
commands[i], (wantname)); \
|
||||||
goto cleanup; \
|
return -1; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
@ -552,13 +550,8 @@ testQemuMonitorJSONGetCommands(const void *opaque)
|
|||||||
CHECK(2, "quit");
|
CHECK(2, "quit");
|
||||||
|
|
||||||
#undef CHECK
|
#undef CHECK
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
cleanup:
|
return 0;
|
||||||
for (i = 0; i < ncommands; i++)
|
|
||||||
VIR_FREE(commands[i]);
|
|
||||||
VIR_FREE(commands);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user