]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Fix memory leaks in 'vix' tools plugin.
authorOliver Kurth <okurth@vmware.com>
Wed, 29 Aug 2018 20:29:45 +0000 (13:29 -0700)
committerOliver Kurth <okurth@vmware.com>
Wed, 29 Aug 2018 20:29:45 +0000 (13:29 -0700)
* 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.

open-vm-tools/services/plugins/vix/vixTools.c

index e52737867a6f7197b2806d33d1f035c6ce0824e8..7df3f91cb6255b72e5a5697647288f6f482eac1f 100644 (file)
@@ -2443,10 +2443,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;
@@ -2647,6 +2647,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.
@@ -11491,7 +11495,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;
@@ -11507,6 +11511,10 @@ done:
    free(username);
    Util_ZeroFreeString(password);
 
+   if (VIX_OK != err) {
+      VGAuth_UserHandleFree(newHandle);
+      newHandle = NULL;
+   }
    return err;
 #else
    return VIX_E_NOT_SUPPORTED;
@@ -11637,7 +11645,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;