Commit:    38eb909d064ecbbf51d5869a629dae91a6ed9dcf
Author:    Xinchen Hui <larue...@php.net>         Tue, 25 Jun 2013 13:37:56 
+0800
Parents:   982c11573dd23d3070dfdd149e4ef1a5a1d14dab
Branches:  PHP-5.4 PHP-5.5 master

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=38eb909d064ecbbf51d5869a629dae91a6ed9dcf

Log:
Fixed Bug #61828 (Memleak when calling 
Directory(Recursive)Iterator/Spl(Temp)FileObject ctor twice)

Bugs:
https://bugs.php.net/61828

Changed paths:
  M  NEWS
  M  ext/spl/spl_directory.c
  A  ext/spl/tests/bug61828.phpt


Diff:
diff --git a/NEWS b/NEWS
index e441cd3..685c037 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 f43a370..056e7e4 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 0000000..04d435e
--- /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


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to