Blame SOURCES/ovt-Fix-memory-leaks-in-vix-tools.patch

8d58a8
From 4e5eb0a6c6996229f4daf3c23398cf62b910637d Mon Sep 17 00:00:00 2001
8d58a8
From: Cathy Avery <cavery@redhat.com>
8d58a8
Date: Fri, 15 Nov 2019 14:49:06 +0100
8d58a8
Subject: [PATCH 1/3] Fix memory leaks in 'vix' tools
8d58a8
8d58a8
RH-Author: Cathy Avery <cavery@redhat.com>
8d58a8
Message-id: <20191115144908.7669-2-cavery@redhat.com>
8d58a8
Patchwork-id: 92388
8d58a8
O-Subject: [RHEL7.7.z open-vm-tools PATCH 1/3] Fix memory leaks in 'vix' tools plugin.
8d58a8
Bugzilla: 1772825
8d58a8
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
8d58a8
RH-Acked-by: Eduardo Otubo <otubo@redhat.com>
8d58a8
8d58a8
commit 015db4c06a8be65eb96cf62421e8b5366993452f
8d58a8
Author: Oliver Kurth <okurth@vmware.com>
8d58a8
Date:   Wed Aug 29 13:29:45 2018 -0700
8d58a8
8d58a8
    Fix memory leaks in 'vix' tools plugin.
8d58a8
8d58a8
    * vix plugin retrieves the power script file paths from the
8d58a8
    config file but doesn't free them and this causes a memory leak.
8d58a8
    Fixed the code to free the filepaths.
8d58a8
8d58a8
    * In GuestAuthPasswordAuthenticateImpersonate function, the VGAuth
8d58a8
    handle is not freed when the impersonation fails. Fixed the
8d58a8
    code to call VGAuth_UserHandleFree in the error path.
8d58a8
8d58a8
    Note: I executed one guest operation with wrong credentials.
8d58a8
    Every failure leaks 75 bytes of memory. (in Centos 64-bit VM)
8d58a8
8d58a8
    * Fixed another minor issue in the code. At couple of places in
8d58a8
    the code, replaced 'err' with 'vgErr' for storing the return value
8d58a8
    of VGAuth_UserHandleAccessToken.
8d58a8
8d58a8
Signed-off-by: Cathy Avery <cavery@redhat.com>
8d58a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
8d58a8
---
8d58a8
 services/plugins/vix/vixTools.c | 20 ++++++++++++++------
8d58a8
 1 file changed, 14 insertions(+), 6 deletions(-)
8d58a8
8d58a8
diff --git a/services/plugins/vix/vixTools.c b/services/plugins/vix/vixTools.c
8d58a8
index 7997fee..7ed9f43 100644
8d58a8
--- a/services/plugins/vix/vixTools.c
8d58a8
+++ b/services/plugins/vix/vixTools.c
8d58a8
@@ -2438,10 +2438,10 @@ VixTools_GetToolsPropertiesImpl(GKeyFile *confDictRef,            // IN
8d58a8
    char *guestName;
8d58a8
    int osFamily;
8d58a8
    char *packageList = NULL;
8d58a8
-   const char *powerOffScript = NULL;
8d58a8
-   const char *powerOnScript = NULL;
8d58a8
-   const char *resumeScript = NULL;
8d58a8
-   const char *suspendScript = NULL;
8d58a8
+   char *powerOffScript = NULL;
8d58a8
+   char *powerOnScript = NULL;
8d58a8
+   char *resumeScript = NULL;
8d58a8
+   char *suspendScript = NULL;
8d58a8
    char *osName = NULL;
8d58a8
    char *osNameFull = NULL;
8d58a8
    Bool foundHostName;
8d58a8
@@ -2642,6 +2642,10 @@ abort:
8d58a8
    free(tempDir);
8d58a8
    free(osName);
8d58a8
    free(osNameFull);
8d58a8
+   free(suspendScript);
8d58a8
+   free(resumeScript);
8d58a8
+   free(powerOnScript);
8d58a8
+   free(powerOffScript);
8d58a8
 #else
8d58a8
    /*
8d58a8
     * FreeBSD. We do not require all the properties above.
8d58a8
@@ -11425,7 +11429,7 @@ GuestAuthPasswordAuthenticateImpersonate(
8d58a8
 
8d58a8
 #ifdef _WIN32
8d58a8
    // this is making a copy of the token, be sure to close it
8d58a8
-   err = VGAuth_UserHandleAccessToken(ctx, newHandle, userToken);
8d58a8
+   vgErr = VGAuth_UserHandleAccessToken(ctx, newHandle, userToken);
8d58a8
    if (VGAUTH_FAILED(vgErr)) {
8d58a8
       err = VixToolsTranslateVGAuthError(vgErr);
8d58a8
       goto done;
8d58a8
@@ -11441,6 +11445,10 @@ done:
8d58a8
    free(username);
8d58a8
    Util_ZeroFreeString(password);
8d58a8
 
8d58a8
+   if (VIX_OK != err) {
8d58a8
+      VGAuth_UserHandleFree(newHandle);
8d58a8
+      newHandle = NULL;
8d58a8
+   }
8d58a8
    return err;
8d58a8
 #else
8d58a8
    return VIX_E_NOT_SUPPORTED;
8d58a8
@@ -11571,7 +11579,7 @@ impersonate:
8d58a8
 
8d58a8
 #ifdef _WIN32
8d58a8
    // this is making a copy of the token, be sure to close it
8d58a8
-   err = VGAuth_UserHandleAccessToken(ctx, newHandle, userToken);
8d58a8
+   vgErr = VGAuth_UserHandleAccessToken(ctx, newHandle, userToken);
8d58a8
    if (VGAUTH_FAILED(vgErr)) {
8d58a8
       err = VixToolsTranslateVGAuthError(vgErr);
8d58a8
       goto done;
8d58a8
-- 
8d58a8
1.8.3.1
8d58a8