summaryrefslogtreecommitdiff
path: root/locale.c
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2019-04-16 16:49:47 +0100
committerDavid Mitchell <davem@iabyn.com>2019-04-16 16:49:47 +0100
commit207cc8dfc710475ee7d8b4dd64a522bd1cf442d3 (patch)
tree1a6cda11a18bc9ad7eac29a27273e7f72d9f414a /locale.c
parent2bfe2a2773c59588ac2bf11b5d9439c92d86fb62 (diff)
downloadperl-207cc8dfc710475ee7d8b4dd64a522bd1cf442d3.tar.gz
fix leak when $LANG unset
The following leaked: LANG= perl -e1 because in S_emulate_setlocale(), it was 1) making a copy of $ENV{"LANG"}; 2) throwing that copy away and replacing it with "C" when it discovered that the string was empty. A little judicious reordering of that chunk of code makes the issue go away. Showed up as failures of lib/locale_threads.t under valgrind / ASan.
Diffstat (limited to 'locale.c')
-rw-r--r--locale.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/locale.c b/locale.c
index 8a1ddc2c20..c3ce587981 100644
--- a/locale.c
+++ b/locale.c
@@ -769,22 +769,19 @@ S_emulate_setlocale(const int category,
const char * default_name;
- /* To minimize other threads messing with the environment, we copy
- * the variable, making it a temporary. But this doesn't work upon
- * program initialization before any scopes are created, and at
- * this time, there's nothing else going on that would interfere.
- * So skip the copy in that case */
- if (PL_scopestack_ix == 0) {
- default_name = PerlEnv_getenv("LANG");
- }
- else {
- default_name = savepv(PerlEnv_getenv("LANG"));
- }
+ default_name = PerlEnv_getenv("LANG");
if (! default_name || strEQ(default_name, "")) {
default_name = "C";
}
else if (PL_scopestack_ix != 0) {
+ /* To minimize other threads messing with the environment,
+ * we copy the variable, making it a temporary. But this
+ * doesn't work upon program initialization before any
+ * scopes are created, and at this time, there's nothing
+ * else going on that would interfere. So skip the copy
+ * in that case */
+ default_name = savepv(default_name);
SAVEFREEPV(default_name);
}