]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
test: testOpenDefault: introduce cleanup path
authorMarc Hartmayer <mhartmay@linux.vnet.ibm.com>
Thu, 8 Mar 2018 12:20:29 +0000 (13:20 +0100)
committerJohn Ferlan <jferlan@redhat.com>
Thu, 15 Mar 2018 21:12:28 +0000 (17:12 -0400)
The two code paths have some cleanup in common so lets refactor it.

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
src/test/test_driver.c

index 043caa976274cdd1296929bd2f04c32b0bb4c83a..31d1fae795df29032053c0fa881e771f8515f1ad 100644 (file)
@@ -1297,6 +1297,7 @@ testOpenFromFile(virConnectPtr conn, const char *file)
 static int
 testOpenDefault(virConnectPtr conn)
 {
+    int ret = VIR_DRV_OPEN_ERROR;
     testDriverPtr privconn = NULL;
     xmlDocPtr doc = NULL;
     xmlXPathContextPtr ctxt = NULL;
@@ -1345,21 +1346,18 @@ testOpenDefault(virConnectPtr conn)
         goto error;
 
     defaultConn = privconn;
-
+    ret = VIR_DRV_OPEN_SUCCESS;
+ cleanup:
+    virMutexUnlock(&defaultLock);
     xmlXPathFreeContext(ctxt);
     xmlFreeDoc(doc);
-    virMutexUnlock(&defaultLock);
-
-    return VIR_DRV_OPEN_SUCCESS;
+    return ret;
 
  error:
     testDriverFree(privconn);
-    xmlXPathFreeContext(ctxt);
-    xmlFreeDoc(doc);
     conn->privateData = NULL;
     defaultConnections--;
-    virMutexUnlock(&defaultLock);
-    return VIR_DRV_OPEN_ERROR;
+    goto cleanup;
 }
 
 static int