com php-src: Fixed bug #71891 (header_register_callback () and register_shutdown_function()): NEW S ext/standard/basic_functions.c
ext/standard/tests/gen eral_functions/bug71891.phpt main/main.c
| From: | Xinchen Hui | Date: | Fri, 25 Mar 2016 04:34:22 +0000 |
| Subject: | com php-src: Fixed bug #71891 (header_register_callback () and register_shutdown_function()): NEW S ext/standard/basic_functions.c ext/standard/tests/gen eral_functions/bug71891.phpt main/main.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-91474@lists.php.net to get a copy of this message | ||
Commit: 1929fc9b16c836c1449dee3fd3570031ff8dcba1
Author: Xinchen Hui <laruence@gmail.com> Fri, 25 Mar 2016 12:34:22 +0800
Parents: 70878a92b181007239a6e9405ec8da32b599c70d
Branches: PHP-7.0 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=1929fc9b16c836c1449dee3fd3570031ff8dcba1
Log:
Fixed bug #71891 (header_register_callback() and register_shutdown_function())
Actually, this fixed the memleak not the behavior(it is expected
behavior that "shutdown" is not outputed)
Bugs:
https://bugs.php.net/71891
Changed paths:
M NEWS
M ext/standard/basic_functions.c
A ext/standard/tests/general_functions/bug71891.phpt
M main/main.c
Diff:
diff --git a/NEWS b/NEWS
index 58d0436..ab38c06 100644
--- a/NEWS
+++ b/NEWS
@@ -42,6 +42,8 @@ PHP NEWS
. Fixed bug #71735 (Double-free in SplDoublyLinkedList::offsetSet). (Stas)
- Standard:
+ . Fixed bug #71891 (header_register_callback() and
+ register_shutdown_function()). (Laruence)
. Fixed bug #71884 (Null pointer deref (segfault) in
stream_context_get_default). (Laruence)
. Fixed bug #71837 (Wrong arrays behaviour). (Laruence)
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index b790f9a..dd61c54 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -5007,7 +5007,6 @@ PHPAPI void php_call_shutdown_functions(void) /* {{{ */
zend_hash_apply(BG(user_shutdown_function_names), user_shutdown_function_call);
}
zend_end_try();
- php_free_shutdown_functions();
}
}
/* }}} */
diff --git a/ext/standard/tests/general_functions/bug71891.phpt
b/ext/standard/tests/general_functions/bug71891.phpt
new file mode 100644
index 0000000..b1f7e20
--- /dev/null
+++ b/ext/standard/tests/general_functions/bug71891.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Bug #71891 (header_register_callback() and register_shutdown_function())
+--FILE--
+<?php
+
+header_register_callback(function () {
+ echo 'header';
+ register_shutdown_function(function () {
+ echo 'shutdown';
+ });
+});
+?>
+--EXPECT--
+header
diff --git a/main/main.c b/main/main.c
index ab87936..fcb42b4 100644
--- a/main/main.c
+++ b/main/main.c
@@ -1712,6 +1712,9 @@ void php_request_shutdown_for_hook(void *dummy)
if (PG(modules_activated)) {
zend_deactivate_modules();
+ }
+
+ if (PG(modules_activated)) {
php_free_shutdown_functions();
}
@@ -1802,7 +1805,6 @@ void php_request_shutdown(void *dummy)
/* 5. Call all extensions RSHUTDOWN functions */
if (PG(modules_activated)) {
zend_deactivate_modules();
- php_free_shutdown_functions();
}
/* 6. Shutdown output layer (send the set HTTP headers, cleanup output handlers, etc.) */
@@ -1810,7 +1812,12 @@ void php_request_shutdown(void *dummy)
php_output_deactivate();
} zend_end_try();
- /* 7. Destroy super-globals */
+ /* 7. Free shutdown functions */
+ if (PG(modules_activated)) {
+ php_free_shutdown_functions();
+ }
+
+ /* 8. Destroy super-globals */
zend_try {
int i;
@@ -1819,37 +1826,37 @@ void php_request_shutdown(void *dummy)
}
} zend_end_try();
- /* 8. free request-bound globals */
+ /* 9. free request-bound globals */
php_free_request_globals();
- /* 9. Shutdown scanner/executor/compiler and restore ini entries */
+ /* 10. Shutdown scanner/executor/compiler and restore ini entries */
zend_deactivate();
- /* 10. Call all extensions post-RSHUTDOWN functions */
+ /* 11. Call all extensions post-RSHUTDOWN functions */
zend_try {
zend_post_deactivate_modules();
} zend_end_try();
- /* 11. SAPI related shutdown (free stuff) */
+ /* 12. SAPI related shutdown (free stuff) */
zend_try {
sapi_deactivate();
} zend_end_try();
- /* 12. free virtual CWD memory */
+ /* 13. free virtual CWD memory */
virtual_cwd_deactivate();
- /* 13. Destroy stream hashes */
+ /* 14. Destroy stream hashes */
zend_try {
php_shutdown_stream_hashes();
} zend_end_try();
- /* 14. Free Willy (here be crashes) */
+ /* 15. Free Willy (here be crashes) */
zend_interned_strings_restore();
zend_try {
shutdown_memory_manager(CG(unclean_shutdown) || !report_memleaks, 0);
} zend_end_try();
- /* 15. Reset max_execution_time */
+ /* 16. Reset max_execution_time */
zend_try {
zend_unset_timeout();
} zend_end_try();