testQemuMonitorJSONGetTPMModels: Refactor cleanup

Use automatic memory freeing and remove the cleanup section.t

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 16:38:26 +02:00
parent d5578879a8
commit d30548aa48

View File

@ -560,8 +560,7 @@ testQemuMonitorJSONGetTPMModels(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) tpmmodels = NULL;
char **tpmmodels = NULL;
int ntpmmodels = 0; int ntpmmodels = 0;
g_autoptr(qemuMonitorTest) test = NULL; g_autoptr(qemuMonitorTest) test = NULL;
@ -574,16 +573,16 @@ testQemuMonitorJSONGetTPMModels(const void *opaque)
" \"passthrough\"" " \"passthrough\""
" ]" " ]"
"}") < 0) "}") < 0)
goto cleanup; return -1;
if ((ntpmmodels = qemuMonitorGetTPMModels(qemuMonitorTestGetMonitor(test), if ((ntpmmodels = qemuMonitorGetTPMModels(qemuMonitorTestGetMonitor(test),
&tpmmodels)) < 0) &tpmmodels)) < 0)
goto cleanup; return -1;
if (ntpmmodels != 1) { if (ntpmmodels != 1) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"ntpmmodels %d is not 1", ntpmmodels); "ntpmmodels %d is not 1", ntpmmodels);
goto cleanup; return -1;
} }
#define CHECK(i, wantname) \ #define CHECK(i, wantname) \
@ -592,7 +591,7 @@ testQemuMonitorJSONGetTPMModels(const void *opaque)
virReportError(VIR_ERR_INTERNAL_ERROR, \ virReportError(VIR_ERR_INTERNAL_ERROR, \
"name %s is not %s", \ "name %s is not %s", \
tpmmodels[i], (wantname)); \ tpmmodels[i], (wantname)); \
goto cleanup; \ return -1; \
} \ } \
} while (0) } while (0)
@ -600,11 +599,7 @@ testQemuMonitorJSONGetTPMModels(const void *opaque)
#undef CHECK #undef CHECK
ret = 0; return 0;
cleanup:
g_strfreev(tpmmodels);
return ret;
} }