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

378f6c
From 01a8304a6c9a93f14ad1c32e15dd2edfd50c8586 Mon Sep 17 00:00:00 2001
8d58a8
From: Cathy Avery <cavery@redhat.com>
378f6c
Date: Fri, 25 Oct 2019 15:34:03 +0200
378f6c
Subject: [PATCH 1/3] Fix memory leaks in 'vix' tools plugin.
8d58a8
8d58a8
RH-Author: Cathy Avery <cavery@redhat.com>
378f6c
Message-id: <20191025153405.10241-2-cavery@redhat.com>
378f6c
Patchwork-id: 91969
378f6c
O-Subject: [RHEL7.8 open-vm-tools PATCH v2 1/3] Fix memory leaks in 'vix' tools plugin.
378f6c
Bugzilla: 1760625
8d58a8
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
378f6c
RH-Acked-by: Miroslav Rezanina <mrezanin@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
378f6c
index 55b1f0a..4436944 100644
8d58a8
--- a/services/plugins/vix/vixTools.c
8d58a8
+++ b/services/plugins/vix/vixTools.c
378f6c
@@ -2522,10 +2522,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;
378f6c
@@ -2726,6 +2726,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.
378f6c
@@ -11583,7 +11587,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;
378f6c
@@ -11599,6 +11603,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;
378f6c
@@ -11729,7 +11737,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