From 3b5b1f9209256de895becc128ad5086a1fc82100 Mon Sep 17 00:00:00 2001 From: Tim Wiederhake Date: Tue, 8 Feb 2022 15:05:35 +0100 Subject: [PATCH] test: Use automatic mutex management Signed-off-by: Tim Wiederhake Reviewed-by: Michal Privoznik --- src/test/test_driver.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 9ceb0b45c8..d9b4d2edf9 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1385,16 +1385,14 @@ testOpenFromFile(virConnectPtr conn, const char *file) static int testOpenDefault(virConnectPtr conn) { - int ret = VIR_DRV_OPEN_ERROR; testDriver *privconn = NULL; g_autoptr(xmlDoc) doc = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; size_t i; + VIR_LOCK_GUARD lock = virLockGuardLock(&defaultLock); - virMutexLock(&defaultLock); if (defaultPrivconn) { conn->privateData = virObjectRef(defaultPrivconn); - virMutexUnlock(&defaultLock); return VIR_DRV_OPEN_SUCCESS; } @@ -1433,15 +1431,12 @@ testOpenDefault(virConnectPtr conn) goto error; defaultPrivconn = privconn; - ret = VIR_DRV_OPEN_SUCCESS; - cleanup: - virMutexUnlock(&defaultLock); - return ret; + return VIR_DRV_OPEN_SUCCESS; error: virObjectUnref(privconn); conn->privateData = NULL; - goto cleanup; + return VIR_DRV_OPEN_ERROR; } static int @@ -1499,12 +1494,12 @@ testConnectAuthenticate(virConnectPtr conn, static void testDriverCloseInternal(testDriver *driver) { - virMutexLock(&defaultLock); + VIR_LOCK_GUARD lock = virLockGuardLock(&defaultLock); + testDriverDisposed = false; virObjectUnref(driver); if (testDriverDisposed && driver == defaultPrivconn) defaultPrivconn = NULL; - virMutexUnlock(&defaultLock); }