[libvirt] [PATCH 06/20] test: testOpenDefault: introduce cleanup path

Marc Hartmayer mhartmay at linux.vnet.ibm.com
Thu Mar 8 12:20:29 UTC 2018


The two code paths have some cleanup in common so lets refactor it.

Signed-off-by: Marc Hartmayer <mhartmay at linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy at linux.vnet.ibm.com>
---
 src/test/test_driver.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 2773f5c758c8..e7307fddad4a 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -1306,6 +1306,7 @@ testOpenFromFile(virConnectPtr conn, const char *file)
 static int
 testOpenDefault(virConnectPtr conn)
 {
+    int ret;
     testDriverPtr privconn = NULL;
     xmlDocPtr doc = NULL;
     xmlXPathContextPtr ctxt = NULL;
@@ -1354,21 +1355,19 @@ 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;
+    ret = VIR_DRV_OPEN_ERROR;
+    goto cleanup;
 }
 
 static int
-- 
2.13.4




More information about the libvir-list mailing list