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 <mprivozn@redhat.com>
This commit is contained in:
Michal Privoznik 2015-02-26 17:13:53 +01:00
parent 3fde7986d6
commit 6954e7da52
3 changed files with 16 additions and 1 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);