[PATCH v2 04/15] test: Extract code to free testDriver into testDriverFree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Avoid reimplementing it 3 times.
---
 src/test/test_driver.c | 55 +++++++++++++++++++++-----------------------------
 1 file changed, 23 insertions(+), 32 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index ff383c6..732dde9 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -135,6 +135,26 @@ static const virNodeInfo defaultNodeInfo = {
     2,
 };

+static void
+testDriverFree(testDriverPtr driver)
+{
+    if (!driver)
+        return;
+
+    virObjectUnref(driver->caps);
+    virObjectUnref(driver->xmlopt);
+    virObjectUnref(driver->domains);
+    virNodeDeviceObjListFree(&driver->devs);
+    virObjectUnref(driver->networks);
+    virInterfaceObjListFree(&driver->ifaces);
+    virStoragePoolObjListFree(&driver->pools);
+    virObjectEventStateFree(driver->eventState);
+    VIR_FREE(driver->path);
+    virMutexUnlock(&driver->lock);
+    virMutexDestroy(&driver->lock);
+
+    VIR_FREE(driver);
+}

 static void testObjectEventQueue(testDriverPtr driver,
                                  virObjectEventPtr event);
@@ -830,16 +850,7 @@ testOpenDefault(virConnectPtr conn)
     return VIR_DRV_OPEN_SUCCESS;

  error:
-    if (privconn) {
-        virObjectUnref(privconn->domains);
-        virObjectUnref(privconn->networks);
-        virInterfaceObjListFree(&privconn->ifaces);
-        virStoragePoolObjListFree(&privconn->pools);
-        virNodeDeviceObjListFree(&privconn->devs);
-        virObjectUnref(privconn->caps);
-        virObjectEventStateFree(privconn->eventState);
-        virMutexDestroy(&privconn->lock);
-    }
+    testDriverFree(privconn);
     conn->privateData = NULL;
     virDomainDefFree(domdef);
     defaultConnections--;
@@ -1465,14 +1476,7 @@ testOpenFromFile(virConnectPtr conn, const char *file)
  error:
     xmlXPathFreeContext(ctxt);
     xmlFreeDoc(doc);
-    virObjectUnref(privconn->domains);
-    virObjectUnref(privconn->networks);
-    virInterfaceObjListFree(&privconn->ifaces);
-    virStoragePoolObjListFree(&privconn->pools);
-    VIR_FREE(privconn->path);
-    virObjectEventStateFree(privconn->eventState);
-    testDriverUnlock(privconn);
-    VIR_FREE(privconn);
+    testDriverFree(privconn);
     conn->privateData = NULL;
     return VIR_DRV_OPEN_ERROR;
 }
@@ -1590,20 +1594,7 @@ static int testConnectClose(virConnectPtr conn)
     }

     testDriverLock(privconn);
-    virObjectUnref(privconn->caps);
-    virObjectUnref(privconn->xmlopt);
-    virObjectUnref(privconn->domains);
-    virNodeDeviceObjListFree(&privconn->devs);
-    virObjectUnref(privconn->networks);
-    virInterfaceObjListFree(&privconn->ifaces);
-    virStoragePoolObjListFree(&privconn->pools);
-    virObjectEventStateFree(privconn->eventState);
-    VIR_FREE(privconn->path);
-
-    testDriverUnlock(privconn);
-    virMutexDestroy(&privconn->lock);
-
-    VIR_FREE(privconn);
+    testDriverFree(privconn);

     if (dflt) {
         defaultConn = NULL;
-- 
2.4.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]