1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-01-11 09:17:52 +03: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:
Peter Krempa 2021-06-14 15:56:16 +02:00
parent ed4c75c4da
commit d5578879a8

View File

@ -502,10 +502,8 @@ testQemuMonitorJSONGetCommands(const void *opaque)
{
const testGenericData *data = opaque;
virDomainXMLOption *xmlopt = data->xmlopt;
int ret = -1;
char **commands = NULL;
g_auto(GStrv) commands = NULL;
int ncommands = 0;
size_t i;
g_autoptr(qemuMonitorTest) test = NULL;
if (!(test = qemuMonitorTestNewSchema(xmlopt, data->schema)))
@ -525,16 +523,16 @@ testQemuMonitorJSONGetCommands(const void *opaque)
" } "
" ]"
"}") < 0)
goto cleanup;
return -1;
if ((ncommands = qemuMonitorGetCommands(qemuMonitorTestGetMonitor(test),
&commands)) < 0)
goto cleanup;
return -1;
if (ncommands != 3) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"ncommands %d is not 3", ncommands);
goto cleanup;
return -1;
}
#define CHECK(i, wantname) \
@ -543,7 +541,7 @@ testQemuMonitorJSONGetCommands(const void *opaque)
virReportError(VIR_ERR_INTERNAL_ERROR, \
"name %s is not %s", \
commands[i], (wantname)); \
goto cleanup; \
return -1; \
} \
} while (0)
@ -552,13 +550,8 @@ testQemuMonitorJSONGetCommands(const void *opaque)
CHECK(2, "quit");
#undef CHECK
ret = 0;
cleanup:
for (i = 0; i < ncommands; i++)
VIR_FREE(commands[i]);
VIR_FREE(commands);
return ret;
return 0;
}