From 35fafe5545d96416d4b7e6f3d6421392c9da0801 Mon Sep 17 00:00:00 2001 From: Owen Yamauchi Date: Wed, 19 Jun 2013 10:14:02 -0700 Subject: [PATCH] Run shutdown handlers before running request-exit cleanup Shutdown handlers can run user code (e.g. the session stuff serializes the session and can pass the serialized blob to user code to do something with), so it's generally not safe to run them after requestExit(). In particular, requestExit destroys global variables, and the session serializer reads $_SESSION. My recent diff to get rid of the hardcoded globals exposed this, though I argue this situation was incorrect all along. --- hphp/runtime/base/program_functions.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hphp/runtime/base/program_functions.cpp b/hphp/runtime/base/program_functions.cpp index b0a2bb7ea..41ab56a24 100644 --- a/hphp/runtime/base/program_functions.cpp +++ b/hphp/runtime/base/program_functions.cpp @@ -1406,11 +1406,14 @@ void hphp_context_exit(ExecutionContext *context, bool psp, Eval::Debugger::InterruptPSPEnded(program); } catch (const Eval::DebuggerException &e) {} } - context->requestExit(); + // Run shutdown handlers. This may cause user code to run. if (shutdown) { context->onRequestShutdown(); } + + // Clean up a bunch of request state. No user code after this point. + context->requestExit(); context->obProtect(false); context->obEndAll(); }