summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXinchen Hui <laruence@php.net>2013-06-25 13:37:56 +0800
committerXinchen Hui <laruence@php.net>2013-06-25 13:38:27 +0800
commit38eb909d064ecbbf51d5869a629dae91a6ed9dcf (patch)
tree21bd68a50ad775c82b18839a4e91fb8cb5381fb7
parent982c11573dd23d3070dfdd149e4ef1a5a1d14dab (diff)
downloadphp-git-38eb909d064ecbbf51d5869a629dae91a6ed9dcf.tar.gz
Fixed Bug #61828 (Memleak when calling Directory(Recursive)Iterator/Spl(Temp)FileObject ctor twice)
-rw-r--r--NEWS4
-rw-r--r--ext/spl/spl_directory.c6
-rw-r--r--ext/spl/tests/bug61828.phpt11
3 files changed, 21 insertions, 0 deletions
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--
+<?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