diff --git a/main/SAPI.c b/main/SAPI.c index 52509e3b017..039ba068270 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -124,7 +124,11 @@ PHP_FUNCTION(header_register_callback) SG(fci_cache) = empty_fcall_info_cache; } - ZVAL_COPY(&SG(callback_func), &fci.function_name); + /* Don't store callback if headers have already been sent: + * It won't get used and we won't have a chance to release it. */ + if (!SG(headers_sent)) { + ZVAL_COPY(&SG(callback_func), &fci.function_name); + } RETURN_TRUE; } diff --git a/tests/basic/header_register_callback_after_output.phpt b/tests/basic/header_register_callback_after_output.phpt new file mode 100644 index 00000000000..eb9931948a2 --- /dev/null +++ b/tests/basic/header_register_callback_after_output.phpt @@ -0,0 +1,9 @@ +--TEST-- +Call header_register_callback() after headers sent +--FILE-- + +--EXPECT-- +Send headers.