[Bf-blender-cvs] [0dbbcaf1e6b] master: Fix: Fix potential memory leak in BLI_getenv
Ray Molenkamp
noreply at git.blender.org
Fri Dec 11 20:09:24 CET 2020
Commit: 0dbbcaf1e6bb8e0296a3754df380badfd372908c
Author: Ray Molenkamp
Date: Fri Dec 11 12:09:18 2020 -0700
Branches: master
https://developer.blender.org/rB0dbbcaf1e6bb8e0296a3754df380badfd372908c
Fix: Fix potential memory leak in BLI_getenv
Issue introduced in rB87b19b3aba0c and unlikely to occur
but no reason not to have correct code.
===================================================================
M source/blender/blenlib/intern/path_util.c
===================================================================
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index 461f8a53beb..927318a923e 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -1322,12 +1322,14 @@ const char *BLI_getenv(const char *env)
if (GetEnvironmentVariableW(env_16, buffer, ARRAY_SIZE(buffer))) {
char *res_utf8 = alloc_utf_8_from_16(buffer, 0);
// make sure the result is valid, and will fit into our temporary storage buffer
- if (res_utf8 && (strlen(res_utf8) + 1) < sizeof(buffer)) {
- // We are re-using the utf16 buffer here, since allocating a second static buffer to
- // contain the UTF-8 version to return would be wasteful.
- memcpy(buffer, res_utf8, strlen(res_utf8) + 1);
+ if (res_utf8) {
+ if (strlen(res_utf8) + 1 < sizeof(buffer)) {
+ // We are re-using the utf16 buffer here, since allocating a second static buffer to
+ // contain the UTF-8 version to return would be wasteful.
+ memcpy(buffer, res_utf8, strlen(res_utf8) + 1);
+ result = (const char *)buffer;
+ }
free(res_utf8);
- result = (const char *)buffer;
}
}
}
@@ -1529,7 +1531,8 @@ bool BLI_path_extension_check_glob(const char *str, const char *ext_fnmatch)
}
/**
- * Does basic validation of the given glob string, to prevent common issues from string truncation.
+ * Does basic validation of the given glob string, to prevent common issues from string
+ * truncation.
*
* For now, only forbids last group to be a wildcard-only one, if there are more than one group
* (i.e. things like "*.txt;*.cpp;*" are changed to "*.txt;*.cpp;")
More information about the Bf-blender-cvs
mailing list