提交 6954e7da 编写于 作者: M Michal Privoznik

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: NMichal Privoznik <mprivozn@redhat.com>
上级 3fde7986
...@@ -264,8 +264,10 @@ parallelsConnectOpen(virConnectPtr conn, ...@@ -264,8 +264,10 @@ parallelsConnectOpen(virConnectPtr conn,
if ((ret = parallelsOpenDefault(conn)) != VIR_DRV_OPEN_SUCCESS || if ((ret = parallelsOpenDefault(conn)) != VIR_DRV_OPEN_SUCCESS ||
(ret = parallelsStorageOpen(conn, flags)) != 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 ret;
}
return VIR_DRV_OPEN_SUCCESS; return VIR_DRV_OPEN_SUCCESS;
} }
...@@ -275,6 +277,9 @@ parallelsConnectClose(virConnectPtr conn) ...@@ -275,6 +277,9 @@ parallelsConnectClose(virConnectPtr conn)
{ {
parallelsConnPtr privconn = conn->privateData; parallelsConnPtr privconn = conn->privateData;
if (!privconn)
return 0;
parallelsNetworkClose(conn); parallelsNetworkClose(conn);
parallelsStorageClose(conn); parallelsStorageClose(conn);
......
...@@ -344,6 +344,10 @@ parallelsNetworkOpen(virConnectPtr conn, ...@@ -344,6 +344,10 @@ parallelsNetworkOpen(virConnectPtr conn,
int parallelsNetworkClose(virConnectPtr conn) int parallelsNetworkClose(virConnectPtr conn)
{ {
parallelsConnPtr privconn = conn->privateData; parallelsConnPtr privconn = conn->privateData;
if (!privconn)
return 0;
parallelsDriverLock(privconn); parallelsDriverLock(privconn);
virNetworkObjListFree(privconn->networks); virNetworkObjListFree(privconn->networks);
VIR_FREE(privconn->networks); VIR_FREE(privconn->networks);
......
...@@ -72,9 +72,15 @@ parallelsStorageClose(virConnectPtr conn) ...@@ -72,9 +72,15 @@ parallelsStorageClose(virConnectPtr conn)
{ {
parallelsConnPtr privconn = conn->privateData; parallelsConnPtr privconn = conn->privateData;
if (!privconn)
return 0;
virStorageDriverStatePtr storageState = privconn->storageState; virStorageDriverStatePtr storageState = privconn->storageState;
privconn->storageState = NULL; privconn->storageState = NULL;
if (!storageState)
return 0;
parallelsStorageLock(storageState); parallelsStorageLock(storageState);
virStoragePoolObjListFree(&privconn->pools); virStoragePoolObjListFree(&privconn->pools);
VIR_FREE(storageState->configDir); VIR_FREE(storageState->configDir);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册