From: Xinchen Hui Date: Tue, 25 Jun 2013 05:37:56 +0000 (+0800) Subject: Fixed Bug #61828 (Memleak when calling Directory(Recursive)Iterator/Spl(Temp)FileObje... X-Git-Tag: php-5.5.2RC1~30^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=38eb909d064ecbbf51d5869a629dae91a6ed9dcf;p=php Fixed Bug #61828 (Memleak when calling Directory(Recursive)Iterator/Spl(Temp)FileObject ctor twice) --- diff --git a/NEWS b/NEWS index e441cd3c41..685c037b0b 100644 --- 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: diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index f43a3709e1..056e7e4f10 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -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 index 0000000000..04d435e6d6 --- /dev/null +++ b/ext/spl/tests/bug61828.phpt @@ -0,0 +1,11 @@ +--TEST-- +Bug #61828 (Memleak when calling Directory(Recursive)Iterator/Spl(Temp)FileObject ctor twice) +--FILE-- +__construct('/tmp'); +echo "Okey"; +?> +--EXPECTF-- +Warning: DirectoryIterator::__construct(): Directory object is already initialized in %sbug61828.php on line 3 +Okey