]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
parallels: fix possible crash in case of errors in prlsdkLoadDomain
authorMaxim Nestratov <mnestratov@parallels.com>
Thu, 21 May 2015 13:49:35 +0000 (16:49 +0300)
committerDmitry Guryanov <dguryanov@parallels.com>
Mon, 25 May 2015 21:11:13 +0000 (00:11 +0300)
Cleanup code in prlsdkLoadDomain doesn't take into account the fact
if private domain structure along with freeing function is assigned
or not. In case it is, we shouldn't call it manually because
virDomainObjListRemove calls it and frees pdom.
Also, allocated def structure should be freed only if it's not
assigned to domain. Otherwise it will be called twice: one time by
virDomainObjListRemove and the second by prlsdkLoadDomain itself.

Signed-off-by: Maxim Nestratov <mnestratov@parallels.com>
src/parallels/parallels_sdk.c

index 553a8775d63f536f300612daad0f4ff2262bb356..bedee2c5f74bcc35e64df92d5e82b5ecb40ce712 100644 (file)
@@ -1379,10 +1379,21 @@ prlsdkLoadDomain(parallelsConnPtr privconn,
 
     return dom;
  error:
-    if (dom && !olddom)
+    if (dom && !olddom) {
+        /* Domain isn't persistent means that we haven't yet set
+         * prlsdkDomObjFreePrivate and should call it manually
+         */
+        if (!dom->persistent)
+            prlsdkDomObjFreePrivate(pdom);
+
         virDomainObjListRemove(privconn->domains, dom);
-    virDomainDefFree(def);
-    prlsdkDomObjFreePrivate(pdom);
+    }
+    /* Delete newly allocated def only if we haven't assigned it to domain
+     * Otherwise we will end up with domain having invalid def within it
+     */
+    if (!dom)
+        virDomainDefFree(def);
+
     return NULL;
 }