From dd9ecf559ed6e5885ccef8b041e4149c2ab2fdbc Mon Sep 17 00:00:00 2001 From: Jordan DeLong Date: Thu, 25 Jul 2013 21:47:04 -0700 Subject: [PATCH] Don't use malloc from pcntl_signal_handler Not kosher. --- hphp/runtime/ext/ext_process.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hphp/runtime/ext/ext_process.cpp b/hphp/runtime/ext/ext_process.cpp index fc671e973..bedc69f3a 100644 --- a/hphp/runtime/ext/ext_process.cpp +++ b/hphp/runtime/ext/ext_process.cpp @@ -20,6 +20,7 @@ #include "hphp/runtime/ext/ext_function.h" #include "hphp/runtime/base/string_buffer.h" #include "hphp/runtime/base/zend_string.h" +#include "hphp/runtime/base/thread_init_fini.h" #include #include #include @@ -281,6 +282,16 @@ public: }; IMPLEMENT_STATIC_REQUEST_LOCAL(SignalHandlers, s_signal_handlers); +// We must register the s_signal_handlers RequestEventHandler +// immediately: otherwise, pcntl_signal_handler might try to register +// it while processing a signal, which means calling malloc to insert +// it into various vectors and sets, which is not ok from a signal +// handler. +const InitFiniNode initSignalHandler( + [] { s_signal_handlers.get(); }, + InitFiniNode::When::ThreadInit +); + static void pcntl_signal_handler(int signo) { if (signo > 0 && signo < _NSIG && !g_context.isNull()) { s_signal_handlers->signaled[signo] = 1;