]> granicus.if.org Git - php/commitdiff
- Fixed memory leak when calling SplFileInfo's constructor twice
authorFelipe Pena <felipe@php.net>
Sun, 11 Mar 2012 15:42:57 +0000 (15:42 +0000)
committerFelipe Pena <felipe@php.net>
Sun, 11 Mar 2012 15:42:57 +0000 (15:42 +0000)
NEWS
ext/spl/spl_directory.c
ext/spl/tests/SplFileInfo_001.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 03a46976db3036a8b621d5ef41a5c84645e86c27..7973b99bedafdf61935a7c4af8af39cfbef2ad55 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -71,6 +71,7 @@ PHP                                                                        NEWS
     chunksize length line is > 10 bytes). (Ilia)
 
 - SPL
+  . Fixed memory leak when calling SplFileInfo's constructor twice. (Felipe)
   . Fixed bug #61347 (inconsistent isset behavior of Arrayobject). (Laruence)
   . Fixed bug #61326 (ArrayObject comparison). (Gustavo)
 
index 01b994b9c3b64838cf417a97d74465555822b4c6..f0e903f0bf57b0426c461d69f3dd1a1ebcd6022f 100755 (executable)
@@ -366,6 +366,10 @@ static zend_object_value spl_filesystem_object_clone(zval *zobject TSRMLS_DC)
 void spl_filesystem_info_set_filename(spl_filesystem_object *intern, char *path, int len, int use_copy TSRMLS_DC) /* {{{ */
 {
        char *p1, *p2;
+       
+       if (intern->file_name) {
+               efree(intern->file_name);
+       }
 
        intern->file_name = use_copy ? estrndup(path, len) : path;
        intern->file_name_len = len;
@@ -386,7 +390,10 @@ void spl_filesystem_info_set_filename(spl_filesystem_object *intern, char *path,
        } else {
                intern->_path_len = 0;
        }
-
+       
+       if (intern->_path) {
+               efree(intern->_path);
+       }
        intern->_path = estrndup(path, intern->_path_len);
 } /* }}} */
 
diff --git a/ext/spl/tests/SplFileInfo_001.phpt b/ext/spl/tests/SplFileInfo_001.phpt
new file mode 100644 (file)
index 0000000..72060f0
--- /dev/null
@@ -0,0 +1,11 @@
+--TEST--
+Testing SplFileInfo calling the constructor twice
+--FILE--
+<?php
+$x = new splfileinfo(1);
+$x->__construct(1);
+
+echo "done!\n";
+?>
+--EXPECT--
+done!