summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTony Cook <tony@develop-help.com>2015-12-09 10:20:46 +1100
committerTony Cook <tony@develop-help.com>2015-12-17 16:46:09 +1100
commite3962106e93fa80bf960e71ac7c7727e7e15eee8 (patch)
treecc4af7b64eeff84578f46dcc6ff53a07927a5ef3
parente685831a3d31399f095db95fd8911f98fd230b3a (diff)
downloadperl-e3962106e93fa80bf960e71ac7c7727e7e15eee8.tar.gz
[perl #126240] use -DPERL_USE_SAFE_PUTENV where possible on OS X
On threaded builds on OS X, libSystem registers atfork handlers that call setenv(), which internally modifies members of environ[], setting them to malloc()ed blocks. In some cases Perl_my_setenv() reallocates environ[] using safesysmalloc(), which under debugging builds adds a tracking header, and if perl_destruct() sees that environ[] has been reallocated, frees it with safesysfree(). When these combine, perl attempts to free the malloc()ed block with safesysfree(), which attempts to access the tracking header, causing an invalid access in tools like valgrind, or a "free from wrong pool" error, since the header contains unrelated data. Avoid this mess by letting libc manage environ[] if unsetenv() is available.
-rw-r--r--hints/darwin.sh10
1 files changed, 10 insertions, 0 deletions
diff --git a/hints/darwin.sh b/hints/darwin.sh
index ee2076013b..2af6ae7331 100644
--- a/hints/darwin.sh
+++ b/hints/darwin.sh
@@ -490,3 +490,13 @@ esac
# makefile in the same place. Since Darwin uses GNU make, this dodges
# the problem.
firstmakefile=GNUmakefile;
+
+# Parts of the system call setenv(), in particular in an atfork handler.
+# This causes problems when the child tries to clean up environ[], so
+# let libc manage environ[].
+cat >> config.over <<'EOOVER'
+if test "$d_unsetenv" = "$define" -a \
+ `expr "$ccflags" : '.*-DPERL_USE_SAFE_PUTENV'` -eq 0; then
+ ccflags="$ccflags -DPERL_USE_SAFE_PUTENV"
+fi
+EOOVER