tests: use g_auto in cpuTestMakeQEMUCaps

Refactor to use automatic cleanup and remove the goto's.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Ján Tomko 2021-08-19 16:32:35 +02:00
parent 55031c09e6
commit e2b5fc9a8b

View File

@ -463,18 +463,18 @@ typedef enum {
static virQEMUCaps * static virQEMUCaps *
cpuTestMakeQEMUCaps(const struct data *data) cpuTestMakeQEMUCaps(const struct data *data)
{ {
virQEMUCaps *qemuCaps = NULL; g_autoptr(virQEMUCaps) qemuCaps = NULL;
qemuMonitorTest *testMon = NULL; g_autoptr(qemuMonitorTest) testMon = NULL;
qemuMonitorCPUModelInfo *model = NULL; g_autoptr(qemuMonitorCPUModelInfo) model = NULL;
virCPUDef *cpu = NULL; g_autoptr(virCPUDef) cpu = NULL;
bool fail_no_props = true; bool fail_no_props = true;
char *json = NULL; g_autofree char *json = NULL;
json = g_strdup_printf("%s/cputestdata/%s-cpuid-%s.json", abs_srcdir, json = g_strdup_printf("%s/cputestdata/%s-cpuid-%s.json", abs_srcdir,
virArchToString(data->arch), data->host); virArchToString(data->arch), data->host);
if (!(testMon = qemuMonitorTestNewFromFile(json, driver.xmlopt, true))) if (!(testMon = qemuMonitorTestNewFromFile(json, driver.xmlopt, true)))
goto error; return NULL;
qemuMonitorTestAllowUnusedCommands(testMon); qemuMonitorTestAllowUnusedCommands(testMon);
@ -488,10 +488,10 @@ cpuTestMakeQEMUCaps(const struct data *data)
if (qemuMonitorGetCPUModelExpansion(qemuMonitorTestGetMonitor(testMon), if (qemuMonitorGetCPUModelExpansion(qemuMonitorTestGetMonitor(testMon),
QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC, QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC,
cpu, true, fail_no_props, &model) < 0) cpu, true, fail_no_props, &model) < 0)
goto error; return NULL;
if (!(qemuCaps = virQEMUCapsNew())) if (!(qemuCaps = virQEMUCapsNew()))
goto error; return NULL;
virQEMUCapsSet(qemuCaps, QEMU_CAPS_KVM); virQEMUCapsSet(qemuCaps, QEMU_CAPS_KVM);
if (data->flags == JSON_MODELS || if (data->flags == JSON_MODELS ||
@ -504,20 +504,9 @@ cpuTestMakeQEMUCaps(const struct data *data)
if (virQEMUCapsProbeCPUDefinitionsTest(qemuCaps, if (virQEMUCapsProbeCPUDefinitionsTest(qemuCaps,
qemuMonitorTestGetMonitor(testMon)) < 0) qemuMonitorTestGetMonitor(testMon)) < 0)
goto error; return NULL;
cleanup: return g_steal_pointer(&qemuCaps);
qemuMonitorCPUModelInfoFree(model);
qemuMonitorTestFree(testMon);
virCPUDefFree(cpu);
VIR_FREE(json);
return qemuCaps;
error:
virObjectUnref(qemuCaps);
qemuCaps = NULL;
goto cleanup;
} }