summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2020-12-06 15:01:14 -0700
committerKarl Williamson <khw@cpan.org>2020-12-19 22:00:30 -0700
commit03694582f8c247d4a1cc8a7bb8348af0173944d7 (patch)
tree663345306aa5475ca4758b0db7a5f026c410c865 /util.c
parent35bcf7ffa2bfeab79ab7b4eb0d35f462775b54d2 (diff)
downloadperl-03694582f8c247d4a1cc8a7bb8348af0173944d7.tar.gz
Fix broken PERL_MEM_LOG under threads
This fixes GH #18341 There are problems with getenv() on threaded perls wchich can lead to incorrect results when compiled with PERL_MEM_LOG. Commit 0b83dfe6dd9b0bda197566adec923f16b9a693cd fixed this for some platforms, but as Tony Cook, pointed out there may be standards-compliant platforms that that didn't fix. The detailed comments outline the issues and (complicated) full solution.
Diffstat (limited to 'util.c')
-rw-r--r--util.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/util.c b/util.c
index 1bfa7f5764..4cd23e8973 100644
--- a/util.c
+++ b/util.c
@@ -5001,14 +5001,13 @@ S_mem_log_common(enum mem_log_type mlt, const UV n,
const char *funcname)
{
const char *pmlenv;
+ dTHX;
PERL_ARGS_ASSERT_MEM_LOG_COMMON;
- /* Use plain getenv() to avoid potential deadlock with PerlEnv_getenv().
- * This means that 'pmlenv' is not protected from other threads overwriting
- * it on platforms where getenv() returns an internal static pointer. See
- * GH #18341 */
- pmlenv = getenv("PERL_MEM_LOG");
+ PL_mem_log[0] |= 0x2; /* Flag that the call is from this code */
+ pmlenv = PerlEnv_getenv("PERL_MEM_LOG");
+ PL_mem_log[0] &= ~0x2;
if (!pmlenv)
return;
if (mlt < MLT_NEW_SV ? strchr(pmlenv,'m') : strchr(pmlenv,'s'))