From 8b43335abb73c97745c377b965d012c5e0ff8152 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Mon, 22 Jun 2015 20:13:12 +0200 Subject: [PATCH] test: Extract code to free testDriver into testDriverFree 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 ff383c65bc..732dde93c8 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;