Skip to content

Commit 1929fc9

Browse files
committed
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)
1 parent 70878a9 commit 1929fc9

File tree

4 files changed

+33
-11
lines changed

4 files changed

+33
-11
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ PHP NEWS
4242
. Fixed bug #71735 (Double-free in SplDoublyLinkedList::offsetSet). (Stas)
4343

4444
- Standard:
45+
. Fixed bug #71891 (header_register_callback() and
46+
register_shutdown_function()). (Laruence)
4547
. Fixed bug #71884 (Null pointer deref (segfault) in
4648
stream_context_get_default). (Laruence)
4749
. Fixed bug #71837 (Wrong arrays behaviour). (Laruence)

ext/standard/basic_functions.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5007,7 +5007,6 @@ PHPAPI void php_call_shutdown_functions(void) /* {{{ */
50075007
zend_hash_apply(BG(user_shutdown_function_names), user_shutdown_function_call);
50085008
}
50095009
zend_end_try();
5010-
php_free_shutdown_functions();
50115010
}
50125011
}
50135012
/* }}} */
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Bug #71891 (header_register_callback() and register_shutdown_function())
3+
--FILE--
4+
<?php
5+
6+
header_register_callback(function () {
7+
echo 'header';
8+
register_shutdown_function(function () {
9+
echo 'shutdown';
10+
});
11+
});
12+
?>
13+
--EXPECT--
14+
header

main/main.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,6 +1712,9 @@ void php_request_shutdown_for_hook(void *dummy)
17121712

17131713
if (PG(modules_activated)) {
17141714
zend_deactivate_modules();
1715+
}
1716+
1717+
if (PG(modules_activated)) {
17151718
php_free_shutdown_functions();
17161719
}
17171720

@@ -1802,15 +1805,19 @@ void php_request_shutdown(void *dummy)
18021805
/* 5. Call all extensions RSHUTDOWN functions */
18031806
if (PG(modules_activated)) {
18041807
zend_deactivate_modules();
1805-
php_free_shutdown_functions();
18061808
}
18071809

18081810
/* 6. Shutdown output layer (send the set HTTP headers, cleanup output handlers, etc.) */
18091811
zend_try {
18101812
php_output_deactivate();
18111813
} zend_end_try();
18121814

1813-
/* 7. Destroy super-globals */
1815+
/* 7. Free shutdown functions */
1816+
if (PG(modules_activated)) {
1817+
php_free_shutdown_functions();
1818+
}
1819+
1820+
/* 8. Destroy super-globals */
18141821
zend_try {
18151822
int i;
18161823

@@ -1819,37 +1826,37 @@ void php_request_shutdown(void *dummy)
18191826
}
18201827
} zend_end_try();
18211828

1822-
/* 8. free request-bound globals */
1829+
/* 9. free request-bound globals */
18231830
php_free_request_globals();
18241831

1825-
/* 9. Shutdown scanner/executor/compiler and restore ini entries */
1832+
/* 10. Shutdown scanner/executor/compiler and restore ini entries */
18261833
zend_deactivate();
18271834

1828-
/* 10. Call all extensions post-RSHUTDOWN functions */
1835+
/* 11. Call all extensions post-RSHUTDOWN functions */
18291836
zend_try {
18301837
zend_post_deactivate_modules();
18311838
} zend_end_try();
18321839

1833-
/* 11. SAPI related shutdown (free stuff) */
1840+
/* 12. SAPI related shutdown (free stuff) */
18341841
zend_try {
18351842
sapi_deactivate();
18361843
} zend_end_try();
18371844

1838-
/* 12. free virtual CWD memory */
1845+
/* 13. free virtual CWD memory */
18391846
virtual_cwd_deactivate();
18401847

1841-
/* 13. Destroy stream hashes */
1848+
/* 14. Destroy stream hashes */
18421849
zend_try {
18431850
php_shutdown_stream_hashes();
18441851
} zend_end_try();
18451852

1846-
/* 14. Free Willy (here be crashes) */
1853+
/* 15. Free Willy (here be crashes) */
18471854
zend_interned_strings_restore();
18481855
zend_try {
18491856
shutdown_memory_manager(CG(unclean_shutdown) || !report_memleaks, 0);
18501857
} zend_end_try();
18511858

1852-
/* 15. Reset max_execution_time */
1859+
/* 16. Reset max_execution_time */
18531860
zend_try {
18541861
zend_unset_timeout();
18551862
} zend_end_try();

0 commit comments

Comments
 (0)