3ac26c9
From: Matthias Bolte <matthias.bolte@googlemail.com>
3ac26c9
Date: Thu, 2 Aug 2018 17:33:37 +0200
3ac26c9
Subject: [PATCH] esx: Fix double-free and freeing static strings in
3ac26c9
 esxDomainSetAutostart
3ac26c9
3ac26c9
Since commit ae83e02f3dd7fe99fed5d8159a35b666fafeafd5#l3393 the
3ac26c9
newPowerInfo pointer itself is used to track the ownership of the
3ac26c9
AutoStartPowerInfo object to make Coverity understand the code better.
3ac26c9
This broke the code that unset some members of the AutoStartPowerInfo
3ac26c9
object that should not be freed the normal way.
3ac26c9
3ac26c9
Instead, transfer ownership of the AutoStartPowerInfo object to the
3ac26c9
HostAutoStartManagerConfig object before filling in the values that
3ac26c9
need special handling. This allows to free the AutoStartPowerInfo
3ac26c9
directly without having to deal with the special values, or to let
3ac26c9
the old (now restored) logic handle the special values again.
3ac26c9
3ac26c9
Signed-off-by: Matthias Bolte <matthias.bolte@googlemail.com>
3ac26c9
Tested-by: Marcos Paulo de Souza <marcos.souza.org@gmail.com>
3ac26c9
Reviewed-by: John Ferlan <jferlan@redhat.com>
3ac26c9
(cherry picked from commit 3ad77f853230f870efa396636e008292c7f2b1c0)
3ac26c9
---
3ac26c9
 src/esx/esx_driver.c | 14 ++++----------
3ac26c9
 1 file changed, 4 insertions(+), 10 deletions(-)
3ac26c9
3ac26c9
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
3ac26c9
index b065cdc513..9a7006c6e5 100644
3ac26c9
--- a/src/esx/esx_driver.c
3ac26c9
+++ b/src/esx/esx_driver.c
3ac26c9
@@ -3422,7 +3422,10 @@ esxDomainSetAutostart(virDomainPtr domain, int autostart)
3ac26c9
     if (esxVI_AutoStartPowerInfo_Alloc(&newPowerInfo) < 0 ||
3ac26c9
         esxVI_Int_Alloc(&newPowerInfo->startOrder) < 0 ||
3ac26c9
         esxVI_Int_Alloc(&newPowerInfo->startDelay) < 0 ||
3ac26c9
-        esxVI_Int_Alloc(&newPowerInfo->stopDelay) < 0) {
3ac26c9
+        esxVI_Int_Alloc(&newPowerInfo->stopDelay) < 0 ||
3ac26c9
+        esxVI_AutoStartPowerInfo_AppendToList(&spec->powerInfo,
3ac26c9
+                                              newPowerInfo) < 0) {
3ac26c9
+        esxVI_AutoStartPowerInfo_Free(&newPowerInfo);
3ac26c9
         goto cleanup;
3ac26c9
     }
3ac26c9
 
3ac26c9
@@ -3434,13 +3437,6 @@ esxDomainSetAutostart(virDomainPtr domain, int autostart)
3ac26c9
     newPowerInfo->stopDelay->value = -1; /* use system default */
3ac26c9
     newPowerInfo->stopAction = (char *)"none";
3ac26c9
 
3ac26c9
-    if (esxVI_AutoStartPowerInfo_AppendToList(&spec->powerInfo,
3ac26c9
-                                              newPowerInfo) < 0) {
3ac26c9
-        goto cleanup;
3ac26c9
-    }
3ac26c9
-
3ac26c9
-    newPowerInfo = NULL;
3ac26c9
-
3ac26c9
     if (esxVI_ReconfigureAutostart
3ac26c9
           (priv->primary,
3ac26c9
            priv->primary->hostSystem->configManager->autoStartManager,
3ac26c9
@@ -3462,8 +3458,6 @@ esxDomainSetAutostart(virDomainPtr domain, int autostart)
3ac26c9
     esxVI_AutoStartDefaults_Free(&defaults);
3ac26c9
     esxVI_AutoStartPowerInfo_Free(&powerInfoList);
3ac26c9
 
3ac26c9
-    esxVI_AutoStartPowerInfo_Free(&newPowerInfo);
3ac26c9
-
3ac26c9
     return result;
3ac26c9
 }
3ac26c9