diff options
author | Ray Molenkamp <github@lazydodo.com> | 2020-12-11 22:09:18 +0300 |
---|---|---|
committer | Ray Molenkamp <github@lazydodo.com> | 2020-12-11 22:09:18 +0300 |
commit | 0dbbcaf1e6bb8e0296a3754df380badfd372908c (patch) | |
tree | 889e5b8edcdfc9ab05cdaba841e5a21129a31023 /source/blender/blenlib/intern/path_util.c | |
parent | bbd7f94d8a51e4a6c57dbcc49cea1fb2afcb8ff3 (diff) |
Fix: Fix potential memory leak in BLI_getenv
Issue introduced in rB87b19b3aba0c and unlikely to occur
but no reason not to have correct code.
Diffstat (limited to 'source/blender/blenlib/intern/path_util.c')
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 15 |
1 files changed, 9 insertions, 6 deletions
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;") |