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