1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-01-11 09:17:52 +03:00

qemusecuritytest: Use AUTOFREE/AUTOUNREF

This simplifies the code a bit and removes the need for cleanup
label in one case. In the other case the label is kept because
it's going to be used later.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Michal Privoznik 2019-04-15 15:34:54 +02:00
parent 1d34d2462e
commit 3c02d383f9

View File

@ -37,29 +37,29 @@ struct testData {
static int static int
prepareObjects(virQEMUDriverPtr driver, prepareObjects(virQEMUDriverPtr driver,
const char *xmlname, const char *xmlname,
virDomainObjPtr *vm) virDomainObjPtr *vm_ret)
{ {
qemuDomainObjPrivatePtr priv; qemuDomainObjPrivatePtr priv;
char *filename = NULL; VIR_AUTOUNREF(virDomainObjPtr) vm = NULL;
char *domxml = NULL; VIR_AUTOFREE(char *) filename = NULL;
int ret = -1; VIR_AUTOFREE(char *) domxml = NULL;
if (virAsprintf(&filename, "%s/qemuxml2argvdata/%s.xml", abs_srcdir, xmlname) < 0) if (virAsprintf(&filename, "%s/qemuxml2argvdata/%s.xml", abs_srcdir, xmlname) < 0)
return -1; return -1;
if (virTestLoadFile(filename, &domxml) < 0) if (virTestLoadFile(filename, &domxml) < 0)
goto cleanup; return -1;
if (!(*vm = virDomainObjNew(driver->xmlopt))) if (!(vm = virDomainObjNew(driver->xmlopt)))
goto cleanup; return -1;
(*vm)->pid = -1; vm->pid = -1;
priv = (*vm)->privateData; priv = vm->privateData;
priv->chardevStdioLogd = false; priv->chardevStdioLogd = false;
priv->rememberOwner = true; priv->rememberOwner = true;
if (!(priv->qemuCaps = virQEMUCapsNew())) if (!(priv->qemuCaps = virQEMUCapsNew()))
goto cleanup; return -1;
virQEMUCapsSetList(priv->qemuCaps, virQEMUCapsSetList(priv->qemuCaps,
QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE, QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE,
@ -75,24 +75,17 @@ prepareObjects(virQEMUDriverPtr driver,
QEMU_CAPS_LAST); QEMU_CAPS_LAST);
if (qemuTestCapsCacheInsert(driver->qemuCapsCache, priv->qemuCaps) < 0) if (qemuTestCapsCacheInsert(driver->qemuCapsCache, priv->qemuCaps) < 0)
goto cleanup; return -1;
if (!((*vm)->def = virDomainDefParseString(domxml, if (!(vm->def = virDomainDefParseString(domxml,
driver->caps, driver->caps,
driver->xmlopt, driver->xmlopt,
NULL, NULL,
0))) 0)))
goto cleanup; return -1;
ret = 0; VIR_STEAL_PTR(*vm_ret, vm);
cleanup: return 0;
if (ret < 0) {
virObjectUnref(*vm);
*vm = NULL;
}
VIR_FREE(domxml);
VIR_FREE(filename);
return ret;
} }
@ -100,7 +93,7 @@ static int
testDomain(const void *opaque) testDomain(const void *opaque)
{ {
const struct testData *data = opaque; const struct testData *data = opaque;
virDomainObjPtr vm = NULL; VIR_AUTOUNREF(virDomainObjPtr) vm = NULL;
int ret = -1; int ret = -1;
if (prepareObjects(data->driver, data->file, &vm) < 0) if (prepareObjects(data->driver, data->file, &vm) < 0)
@ -109,7 +102,7 @@ testDomain(const void *opaque)
/* Mocking is enabled only when this env variable is set. /* Mocking is enabled only when this env variable is set.
* See mock code for explanation. */ * See mock code for explanation. */
if (setenv(ENVVAR, "1", 0) < 0) if (setenv(ENVVAR, "1", 0) < 0)
goto cleanup; return -1;
if (qemuSecuritySetAllLabel(data->driver, vm, NULL) < 0) if (qemuSecuritySetAllLabel(data->driver, vm, NULL) < 0)
goto cleanup; goto cleanup;
@ -122,7 +115,6 @@ testDomain(const void *opaque)
ret = 0; ret = 0;
cleanup: cleanup:
unsetenv(ENVVAR); unsetenv(ENVVAR);
virObjectUnref(vm);
freePaths(); freePaths();
return ret; return ret;
} }