From: Oliver Kurth Date: Tue, 30 Apr 2019 20:24:25 +0000 (-0700) Subject: Provide a shutdown function for users of the unicode library to free memory X-Git-Tag: stable-11.0.0~100 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9bec96154c23462f2c6f80dd660f41bba38d4614;p=thirdparty%2Fopen-vm-tools.git Provide a shutdown function for users of the unicode library to free memory allocated by Unicode_Init(). Most applications using the unicode library do not free related memory since they are about to terminate. A Unicode_Shutdown() function is provided which will explicitly free the memory allocated by Unicode_Init(). --- diff --git a/open-vm-tools/lib/include/unicodeTypes.h b/open-vm-tools/lib/include/unicodeTypes.h index f47154334..1b38a62f6 100644 --- a/open-vm-tools/lib/include/unicodeTypes.h +++ b/open-vm-tools/lib/include/unicodeTypes.h @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2007-2017 VMware, Inc. All rights reserved. + * Copyright (C) 2007-2017, 2019 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 @@ -456,6 +456,8 @@ void Unicode_InitW(int argc, utf16_t **wargv, utf16_t **wenvp, char ***argv, char ***envp); #endif +void Unicode_Shutdown(int argc, char **argv, char **envp); + StringEncoding Unicode_GetCurrentEncoding(void); StringEncoding Unicode_ResolveEncoding(StringEncoding encoding); diff --git a/open-vm-tools/lib/unicode/unicodeSimpleTypes.c b/open-vm-tools/lib/unicode/unicodeSimpleTypes.c index c721a79ea..eb157fba5 100644 --- a/open-vm-tools/lib/unicode/unicodeSimpleTypes.c +++ b/open-vm-tools/lib/unicode/unicodeSimpleTypes.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2007-2018 VMware, Inc. All rights reserved. + * Copyright (C) 2007-2019 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 @@ -2779,6 +2779,9 @@ Unicode_IsEncodingValid(StringEncoding encoding) // IN * native code set name. The cached name is used to resolve references * to STRING_ENCODING_DEFAULT in unicode functions. * + * argv/envp will be rewritten to point to newly allocated memory. This + * memory should be freed by calling Unicode_Shutdown(). + * *----------------------------------------------------------------------------- */ @@ -2912,6 +2915,37 @@ Unicode_Init(int argc, // IN UnicodeInitInternal(argc, NULL, NULL, NULL, argv, envp); } + +/* + *----------------------------------------------------------------------------- + * + * Unicode_Shutdown -- + * + * Frees memory allocated by UnicodeInitInternal(). + * + * Results: + * None + * + * Side effects: + * None + * + *----------------------------------------------------------------------------- + */ + +void +Unicode_Shutdown(int argc, // IN + char **argv, // IN (OPT) + char **envp) // IN (OPT) +{ + if (argv != NULL) { + Util_FreeStringList(argv, argc + 1); + } + + if (envp != NULL) { + Util_FreeStringList(envp, -1); + } +} + #ifdef TEST_CUSTOM_ICU_DATA_FILE /* *-----------------------------------------------------------------------------