]> granicus.if.org Git - php/commitdiff
Fixed Bug #61828 (Memleak when calling Directory(Recursive)Iterator/Spl(Temp)FileObje...
authorXinchen Hui <laruence@php.net>
Tue, 25 Jun 2013 05:37:56 +0000 (13:37 +0800)
committerXinchen Hui <laruence@php.net>
Tue, 25 Jun 2013 05:38:27 +0000 (13:38 +0800)
NEWS
ext/spl/spl_directory.c
ext/spl/tests/bug61828.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index e441cd3c41b96b9f7b9fd05ff0467c677dba4a45..685c037b0b3b2bdd14a117d09b874415622ca922 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -23,6 +23,10 @@ PHP                                                                        NEWS
   . Implemented FR #63472 (Setting SO_BINDTODEVICE with socket_set_option). 
     (Damjan Cvetko)
 
+- SPL:
+  . Fixed bug #61828 (Memleak when calling Directory(Recursive)Iterator
+    /Spl(Temp)FileObject ctor twice). (Laruence)
+
 ?? ??? 2013, PHP 5.4.17
 
 - Core:
index f43a3709e13080dcd430add5160eb29a744e515b..056e7e4f103ae3a023b36887b545c83f0b737288 100644 (file)
@@ -710,6 +710,12 @@ void spl_filesystem_object_construct(INTERNAL_FUNCTION_PARAMETERS, long ctor_fla
        }
 
        intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+       if (intern->_path) {
+               /* object is alreay initialized */
+               zend_restore_error_handling(&error_handling TSRMLS_CC);
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Directory object is already initialized");
+               return;
+       }
        intern->flags = flags;
 #ifdef HAVE_GLOB
        if (SPL_HAS_FLAG(ctor_flags, DIT_CTOR_GLOB) && strstr(path, "glob://") != path) {
diff --git a/ext/spl/tests/bug61828.phpt b/ext/spl/tests/bug61828.phpt
new file mode 100644 (file)
index 0000000..04d435e
--- /dev/null
@@ -0,0 +1,11 @@
+--TEST--
+Bug #61828 (Memleak when calling Directory(Recursive)Iterator/Spl(Temp)FileObject ctor twice)
+--FILE--
+<?php
+$x = new DirectoryIterator('.');
+$x->__construct('/tmp');
+echo "Okey";
+?>
+--EXPECTF--
+Warning: DirectoryIterator::__construct(): Directory object is already initialized in %sbug61828.php on line 3
+Okey