In a lot of cases we do plain virObjectUnref() with the domain
object lock held. While this looks okay, what really happens
under the hood is that we destroy a locked mutex. But with a help
from virDomainObjEndAPI() we can do the right thing and unlock
the mutex before destroying it.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
tests/qemuhotplugtest.c | 13 +++++--------
tests/qemusecuritytest.c | 3 ++-
tests/qemuxml2argvtest.c | 22 +++++++++++++---------
3 files changed, 20 insertions(+), 18 deletions(-)
diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c
index 263a92425c..de136f7987 100644
--- a/tests/qemuhotplugtest.c
+++ b/tests/qemuhotplugtest.c
@@ -278,7 +278,7 @@ testQemuHotplug(const void *data)
goto cleanup;
if (test->vm) {
- vm = test->vm;
+ vm = g_steal_pointer(&test->vm);
if (!vm->def) {
VIR_TEST_VERBOSE("test skipped due to failure of dependent test");
goto cleanup;
@@ -352,12 +352,9 @@ testQemuHotplug(const void *data)
/* don't dispose test monitor with VM */
if (priv)
priv->mon = NULL;
- if (keep) {
- test->vm = vm;
- } else {
- virObjectUnref(vm);
- test->vm = NULL;
- }
+ if (keep)
+ test->vm = g_steal_pointer(&vm);
+ virDomainObjEndAPI(&vm);
virDomainDeviceDefFree(dev);
return ((ret < 0 && fail) || (!ret && !fail)) ? 0 : -1;
}
@@ -397,7 +394,7 @@ testQemuHotplugCpuDataFree(struct testQemuHotplugCpuData *data)
priv = data->vm->privateData;
priv->mon = NULL;
- virObjectUnref(data->vm);
+ virDomainObjEndAPI(&data->vm);
}
if (data->mon) {
diff --git a/tests/qemusecuritytest.c b/tests/qemusecuritytest.c
index 924c625a4c..2a7641dc83 100644
--- a/tests/qemusecuritytest.c
+++ b/tests/qemusecuritytest.c
@@ -86,7 +86,7 @@ static int
testDomain(const void *opaque)
{
const struct testData *data = opaque;
- g_autoptr(virDomainObj) vm = NULL;
+ virDomainObj *vm = NULL;
g_autoptr(GHashTable) notRestored = virHashNew(NULL);
size_t i;
int ret = -1;
@@ -126,6 +126,7 @@ testDomain(const void *opaque)
ret = 0;
cleanup:
+ virDomainObjEndAPI(&vm);
g_unsetenv(ENVVAR);
freePaths();
return ret;
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 6cf35a0ebf..794d76c776 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -642,11 +642,12 @@ testCompareXMLToArgvValidateSchema(virQEMUDriver *drv,
unsigned int flags)
{
g_auto(GStrv) args = NULL;
- g_autoptr(virDomainObj) vm = NULL;
+ virDomainObj *vm = NULL;
qemuDomainObjPrivate *priv = NULL;
GHashTable *schema = NULL;
g_autoptr(virCommand) cmd = NULL;
unsigned int parseFlags = info->parseFlags;
+ int ret = -1;
/* comment out with line comment to enable schema checking for non _CAPS tests
if (!info->schemafile)
@@ -669,29 +670,32 @@ testCompareXMLToArgvValidateSchema(virQEMUDriver *drv,
return 0;
if (!(vm = virDomainObjNew(driver.xmlopt)))
- return -1;
+ goto cleanup;
parseFlags |= VIR_DOMAIN_DEF_PARSE_INACTIVE;
if (!(vm->def = virDomainDefParseFile(info->infile,
driver.xmlopt,
NULL, parseFlags)))
- return -1;
+ goto cleanup;
priv = vm->privateData;
if (virBitmapParse("0-3", &priv->autoNodeset, 4) < 0)
- return -1;
+ goto cleanup;
if (!(cmd = testCompareXMLToArgvCreateArgs(drv, vm, migrateURI, info, flags)))
- return -1;
+ goto cleanup;
if (virCommandGetArgList(cmd, &args) < 0)
- return -1;
+ goto cleanup;
if (testCompareXMLToArgvValidateSchemaCommand(args, schema) < 0)
- return -1;
+ goto cleanup;
- return 0;
+ ret = 0;
+ cleanup:
+ virDomainObjEndAPI(&vm);
+ return ret;
}
@@ -885,7 +889,7 @@ testCompareXMLToArgv(const void *data)
cleanup:
virDomainChrSourceDefClear(&monitor_chr);
- virObjectUnref(vm);
+ virDomainObjEndAPI(&vm);
virIdentitySetCurrent(NULL);
virSetConnectSecret(NULL);
virSetConnectStorage(NULL);
--
2.34.1