]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Properly free the memory when RpcChannel_Send() fails.
authorOliver Kurth <okurth@vmware.com>
Mon, 20 Aug 2018 19:48:07 +0000 (12:48 -0700)
committerOliver Kurth <okurth@vmware.com>
Mon, 20 Aug 2018 19:48:07 +0000 (12:48 -0700)
At few places in the code, when RpcChannel_Send() function fails,
the result (fourth argument to the function) is not freed which might
result in a memory leak.

Addressed few references by adding 'RpcChannel_Free(...)' calls
in the necessary error code paths.

For toolbox-cmd application, added a new function ToolsCmd_FreeRPC
which internally calls RpcChannel_Free function to free the memory
allocated from ToolsCmd_SendRPC calls. Modified toolboxcmd-shrink.c
to use the new function to free the memory.

open-vm-tools/services/plugins/grabbitmqProxy/grabbitmqProxyPlugin.c
open-vm-tools/toolbox/toolbox-cmd.c
open-vm-tools/toolbox/toolboxCmdInt.h
open-vm-tools/toolbox/toolboxcmd-shrink.c

index 03700937fd1f7744b9e0a775e1b87a84499fba11..69a653ca4512a264505ac3fa422bb710bfa4cf1b 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2012-2017 VMware, Inc. All rights reserved.
+ * Copyright (C) 2012-2018 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -1590,7 +1590,7 @@ static char *
 GetVmVcUuidFromVmx(void)
 {
    char *vcUuid;
-   char *reply;
+   char *reply = NULL;
    size_t replyLen;
    gboolean ok;
    gchar *msg = "xrabbitmqProxy.getVmVcUuid";
@@ -1601,12 +1601,14 @@ GetVmVcUuidFromVmx(void)
    if (!ok) {
       g_warning("Guest rpc call to VMX failed, "
                 "cannot retrieve vc uuid from vmx.\n");
+      RpcChannel_Free(reply);
       return NULL;
    }
 
    if (replyLen > VC_UUID_SIZE) {
       g_warning("Guest rpc call to VMX failed, "
                 "the returned vc uuid too large.\n");
+      RpcChannel_Free(reply);
       return NULL;
    }
 
@@ -1616,6 +1618,7 @@ GetVmVcUuidFromVmx(void)
    g_info("Guest rpc call to VMX, retrieved vc uuid %s\n",
           vcUuid);
 
+   RpcChannel_Free(reply);
    return vcUuid;
 }
 
index 450b00709d37abf94a9f49ed8fea5c9b9f23ce68..45a12ef4b1a73e1eb4a858f39b91a778e5202f8d 100644 (file)
@@ -1,6 +1,6 @@
 
 /*********************************************************
- * Copyright (C) 2008-2017 VMware, Inc. All rights reserved.
+ * Copyright (C) 2008-2018 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -247,6 +247,30 @@ exit:
 }
 
 
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * ToolsCmd_FreeRPC --
+ *
+ *    Free the memory allocated for the results from
+ *    ToolsCmd_SendRPC calls.
+ *
+ * Results:
+ *    None.
+ *
+ * Side effects:
+ *    None.
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+void
+ToolsCmd_FreeRPC(void *ptr)      // IN
+{
+   RpcChannel_Free(ptr);
+}
+
+
 /*
  *-----------------------------------------------------------------------------
  *
index 1ce0dbab1f920c1c82c36f59df56e8b4c542bd3c..b55e8ecd1e17609b22d0a876b9955ae3f3d4e2e7 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2008-2017 VMware, Inc. All rights reserved.
+ * Copyright (C) 2008-2018 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -104,6 +104,9 @@ ToolsCmd_SendRPC(const char *rpc,
                  char **result,
                  size_t *resultLen);
 
+void
+ToolsCmd_FreeRPC(void *ptr);
+
 /*
  * Command declarations.
  */
index 8774fa43793a62709f4e05d6aa26abb708f867ee..4e3e72472c876d22c0bd81d8f05769dae1e5f664 100644 (file)
@@ -105,7 +105,7 @@ ShrinkGetWiperState(void)
          state = WIPER_DISABLED;
       }
    }
-   free(result);
+   ToolsCmd_FreeRPC(result);
    return state;
 }
 
@@ -234,8 +234,9 @@ ShrinkList(void)
 static int
 ShrinkDiskSendRPC(void)
 {
-   char *result;
+   char *result = NULL;
    size_t resultLen;
+   int retVal;
 
    ToolsCmd_PrintErr("\n");
 
@@ -243,11 +244,15 @@ ShrinkDiskSendRPC(void)
                         &result, &resultLen)) {
       ToolsCmd_Print("%s",
                      SU_(disk.shrink.complete, "Disk shrinking complete.\n"));
-      return EXIT_SUCCESS;
+      retVal =  EXIT_SUCCESS;
+   } else {
+      ToolsCmd_PrintErr(SU_(disk.shrink.error,
+                        "Error while shrinking: %s\n"), result);
+      retVal =  EX_TEMPFAIL;
    }
 
-   ToolsCmd_PrintErr(SU_(disk.shrink.error, "Error while shrinking: %s\n"), result);
-   return EX_TEMPFAIL;
+   ToolsCmd_FreeRPC(result);
+   return retVal;
 }