From 6954e7da52fa342ca137d1c84eed07136b3031c3 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Thu, 26 Feb 2015 17:13:53 +0100 Subject: [PATCH] parallels: Cleanup partly opened drivers on connect open failure Well, the parallelsConnectOpen() joins several sub-driver openings into one big if condition. If any of sub-driver fails to open, the whole API finishes immediately. The problem is, sub-drivers may have left some memory allocated. Fortunately, we have a free function for that: parallelsConnectClose(). This is, however, not prepared for partially allocated driver structure. So, prepare the free function for it and call it at the right place, in the if body. Signed-off-by: Michal Privoznik --- src/parallels/parallels_driver.c | 7 ++++++- src/parallels/parallels_network.c | 4 ++++ src/parallels/parallels_storage.c | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c index c9338b5be0..650b79051e 100644 --- a/src/parallels/parallels_driver.c +++ b/src/parallels/parallels_driver.c @@ -264,8 +264,10 @@ parallelsConnectOpen(virConnectPtr conn, if ((ret = parallelsOpenDefault(conn)) != VIR_DRV_OPEN_SUCCESS || (ret = parallelsStorageOpen(conn, flags)) != VIR_DRV_OPEN_SUCCESS || - (ret = parallelsNetworkOpen(conn, flags)) != VIR_DRV_OPEN_SUCCESS) + (ret = parallelsNetworkOpen(conn, flags)) != VIR_DRV_OPEN_SUCCESS) { + parallelsConnectClose(conn); return ret; + } return VIR_DRV_OPEN_SUCCESS; } @@ -275,6 +277,9 @@ parallelsConnectClose(virConnectPtr conn) { parallelsConnPtr privconn = conn->privateData; + if (!privconn) + return 0; + parallelsNetworkClose(conn); parallelsStorageClose(conn); diff --git a/src/parallels/parallels_network.c b/src/parallels/parallels_network.c index a347a09413..e1c6040deb 100644 --- a/src/parallels/parallels_network.c +++ b/src/parallels/parallels_network.c @@ -344,6 +344,10 @@ parallelsNetworkOpen(virConnectPtr conn, int parallelsNetworkClose(virConnectPtr conn) { parallelsConnPtr privconn = conn->privateData; + + if (!privconn) + return 0; + parallelsDriverLock(privconn); virNetworkObjListFree(privconn->networks); VIR_FREE(privconn->networks); diff --git a/src/parallels/parallels_storage.c b/src/parallels/parallels_storage.c index a6980a477a..6397601aa9 100644 --- a/src/parallels/parallels_storage.c +++ b/src/parallels/parallels_storage.c @@ -72,9 +72,15 @@ parallelsStorageClose(virConnectPtr conn) { parallelsConnPtr privconn = conn->privateData; + if (!privconn) + return 0; + virStorageDriverStatePtr storageState = privconn->storageState; privconn->storageState = NULL; + if (!storageState) + return 0; + parallelsStorageLock(storageState); virStoragePoolObjListFree(&privconn->pools); VIR_FREE(storageState->configDir); -- GitLab