]> granicus.if.org Git - php/commitdiff
Fixed bug #71204 (segfault if clean spl_autoload_funcs while autoloading)
authorXinchen Hui <laruence@gmail.com>
Wed, 23 Dec 2015 16:10:59 +0000 (08:10 -0800)
committerXinchen Hui <laruence@gmail.com>
Wed, 23 Dec 2015 16:10:59 +0000 (08:10 -0800)
NEWS
ext/spl/php_spl.c
ext/spl/tests/bug71204.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index e460e3438eed310af27f0b54a82a9fb637d7d7a4..0776f3f5f816d521a752877e1d972d674c79408d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,10 @@ PHP                                                                        NEWS
 - Session:
   . Fixed bug #71122 (Session GC may not remove obsolete session data). (Yasuo)
 
+- SPL:
+  . Fixed bug #71204 (segfault if clean spl_autoload_funcs while autoloading).
+    (Laruence)
+
 - Standard:
   . Fixed bug #70720 (strip_tags improper php code parsing). (Julien)
     
index 3424b90aeaa2ebbbd4b54faa42bd0cc6aa2a35cb..d3228698de0e9c8f993abf4ed5ce36e93be854db 100644 (file)
@@ -669,10 +669,14 @@ PHP_FUNCTION(spl_autoload_unregister)
        if (SPL_G(autoload_functions)) {
                if (func_name_len == sizeof("spl_autoload_call")-1 && !strcmp(lc_name, "spl_autoload_call")) {
                        /* remove all */
-                       zend_hash_destroy(SPL_G(autoload_functions));
-                       FREE_HASHTABLE(SPL_G(autoload_functions));
-                       SPL_G(autoload_functions) = NULL;
-                       EG(autoload_func) = NULL;
+                       if (!SPL_G(autoload_running)) {
+                               zend_hash_destroy(SPL_G(autoload_functions));
+                               FREE_HASHTABLE(SPL_G(autoload_functions));
+                               SPL_G(autoload_functions) = NULL;
+                               EG(autoload_func) = NULL;
+                       } else {
+                               zend_hash_clean(SPL_G(autoload_functions));
+                       }
                        success = SUCCESS;
                } else {
                        /* remove specific */
diff --git a/ext/spl/tests/bug71204.phpt b/ext/spl/tests/bug71204.phpt
new file mode 100644 (file)
index 0000000..01a9f3b
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+Bug #71204 (segfault if clean spl_autoload_funcs while autoloading )
+--FILE--
+<?php
+
+spl_autoload_register(function ($name) {
+       spl_autoload_unregister("spl_autoload_call");
+});
+
+spl_autoload_register(function ($name) {
+});
+
+new A();
+?>
+--EXPECTF--
+Fatal error: Cannot destroy active lambda function in %sbug71204.php on line %d