]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Provide a shutdown function for users of the unicode library to free memory
authorOliver Kurth <okurth@vmware.com>
Tue, 30 Apr 2019 20:24:25 +0000 (13:24 -0700)
committerOliver Kurth <okurth@vmware.com>
Tue, 30 Apr 2019 20:24:25 +0000 (13:24 -0700)
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().

open-vm-tools/lib/include/unicodeTypes.h
open-vm-tools/lib/unicode/unicodeSimpleTypes.c

index f47154334045fb3b83899c17e85cb5fd5f36fd83..1b38a62f69b1a0581459c3d5b34a3f5d2baf765d 100644 (file)
@@ -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);
 
index c721a79ea789e24c94e16c3596dfa2ca246aa607..eb157fba55ca14bf90f3c5e23b3a6c94eb61fc0d 100644 (file)
@@ -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
 /*
  *-----------------------------------------------------------------------------