There are two ways how a domain object can appear in
_qemuMonitorTest structure. Either it was created by
qemuMonitorCommonTestNew() or caller created the object and we
are just leasing it.
But this also means we have to release the domain object
differently. If the domain object was created by us, then we must
unlock and unref it (which is what virDomainObjEndAPI()) does,
but if it just a leased object then we have to refrain from
unlocking it because this would create lock/unlock imbalance.
Moreover, caller might want to keep the object locked.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
tests/qemumonitortestutils.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c
index 86300da68a..bb7a8e1191 100644
--- a/tests/qemumonitortestutils.c
+++ b/tests/qemumonitortestutils.c
@@ -84,6 +84,7 @@ struct _qemuMonitorTest {
qemuMonitorTestItem **items;
virDomainObj *vm;
+ bool vm_created;
GHashTable *qapischema;
};
@@ -406,7 +407,10 @@ qemuMonitorTestFree(qemuMonitorTest *test)
g_object_unref(test->eventThread);
- virObjectUnref(test->vm);
+ if (test->vm_created)
+ virDomainObjEndAPI(&test->vm);
+ else
+ virObjectUnref(test->vm);
if (test->started)
virThreadJoin(&test->thread);
@@ -1025,6 +1029,7 @@ qemuMonitorCommonTestNew(virDomainXMLOption *xmlopt,
return NULL;
if (!(test->vm->def = virDomainDefNew(xmlopt)))
return NULL;
+ test->vm_created = true;
}
if (virNetSocketNewListenUNIX(path, 0700, geteuid(), getegid(),
--
2.34.1