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; 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;
} }