From: Oliver Kurth Date: Mon, 20 Aug 2018 19:48:07 +0000 (-0700) Subject: Properly free the memory when RpcChannel_Send() fails. X-Git-Tag: stable-11.0.0~474 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=251ca7762ecddfe052f3b8f2c879a9fcb714fb4c;p=thirdparty%2Fopen-vm-tools.git Properly free the memory when RpcChannel_Send() fails. 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. --- diff --git a/open-vm-tools/services/plugins/grabbitmqProxy/grabbitmqProxyPlugin.c b/open-vm-tools/services/plugins/grabbitmqProxy/grabbitmqProxyPlugin.c index 03700937f..69a653ca4 100644 --- a/open-vm-tools/services/plugins/grabbitmqProxy/grabbitmqProxyPlugin.c +++ b/open-vm-tools/services/plugins/grabbitmqProxy/grabbitmqProxyPlugin.c @@ -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; } diff --git a/open-vm-tools/toolbox/toolbox-cmd.c b/open-vm-tools/toolbox/toolbox-cmd.c index 450b00709..45a12ef4b 100644 --- a/open-vm-tools/toolbox/toolbox-cmd.c +++ b/open-vm-tools/toolbox/toolbox-cmd.c @@ -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); +} + + /* *----------------------------------------------------------------------------- * diff --git a/open-vm-tools/toolbox/toolboxCmdInt.h b/open-vm-tools/toolbox/toolboxCmdInt.h index 1ce0dbab1..b55e8ecd1 100644 --- a/open-vm-tools/toolbox/toolboxCmdInt.h +++ b/open-vm-tools/toolbox/toolboxCmdInt.h @@ -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. */ diff --git a/open-vm-tools/toolbox/toolboxcmd-shrink.c b/open-vm-tools/toolbox/toolboxcmd-shrink.c index 8774fa437..4e3e72472 100644 --- a/open-vm-tools/toolbox/toolboxcmd-shrink.c +++ b/open-vm-tools/toolbox/toolboxcmd-shrink.c @@ -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; }