]> granicus.if.org Git - php/commitdiff
Fixed bug #70249 (Segmentation fault while running PHPUnit tests on phpBB 3.2-dev)
authorXinchen Hui <laruence@gmail.com>
Wed, 11 Nov 2015 03:33:32 +0000 (11:33 +0800)
committerXinchen Hui <laruence@gmail.com>
Wed, 11 Nov 2015 03:34:11 +0000 (11:34 +0800)
Maybe we should introduce a new zend_hash_safe_apply which always reload
the ht->arData to make sure won't segfault the ht is grew?

NEWS
ext/standard/basic_functions.c
ext/standard/tests/general_functions/bug70249.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 6a88338f6e8958ba5195aa74f9c951c7b19961b8..3ebc7de1e77be350f7bcbfbc11a2ad3cbc3fc88b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,10 @@ PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2015, PHP 7.0.1
 
+- Standard:
+  . Fixed bug #70249 (Segmentation fault while running PHPUnit tests on
+    phpBB 3.2-dev). (Laruence)
+
 - Streams/Socket
   . Add IPV6_V6ONLY constant / make it usable in stream contexts. (Bob)
 
index 8da45c428768b838de00925983d788b48ca11c95..1c5f3fe988b3cd79b22e798b4f7b1e4d89ab2bb3 100644 (file)
@@ -5002,9 +5002,16 @@ PHPAPI void php_call_shutdown_functions(void) /* {{{ */
 {
        if (BG(user_shutdown_function_names)) {
                zend_try {
-                       zend_hash_apply(BG(user_shutdown_function_names), user_shutdown_function_call);
-               }
-               zend_end_try();
+                       zval *entry;
+                       for (zend_hash_internal_pointer_reset(BG(user_shutdown_function_names));
+                                       zend_hash_has_more_elements(BG(user_shutdown_function_names)) == SUCCESS;
+                                       zend_hash_move_forward(BG(user_shutdown_function_names))) {
+                               if ((entry = zend_hash_get_current_data(BG(user_shutdown_function_names))) == NULL) {
+                                       continue;
+                               }
+                               user_shutdown_function_call(entry);
+                       }
+               } zend_end_try();
                php_free_shutdown_functions();
        }
 }
diff --git a/ext/standard/tests/general_functions/bug70249.phpt b/ext/standard/tests/general_functions/bug70249.phpt
new file mode 100644 (file)
index 0000000..aed8dcc
--- /dev/null
@@ -0,0 +1,28 @@
+--TEST--
+Bug #70249 (Segmentation fault while running PHPUnit tests on phpBB 3.2-dev)
+--FILE--
+<?php
+
+class Logger {
+    public function __construct() {
+        register_shutdown_function(function () {
+            // make regular flush before other shutdown functions, which allows session data collection and so on
+            $this->flush();
+            // make sure log entries written by shutdown functions are also flushed
+            // ensure "flush()" is called last when there are multiple shutdown functions
+            register_shutdown_function([$this, 'flush'], true);
+        });
+    }
+    
+    public function flush($final = false) {
+        return 1;
+    }
+}
+
+for ($i = 0; $i < 200; $i++) {
+    $a = new Logger();   
+}
+?>
+okey
+--EXPECT--
+okey