diff options
author | Felipe Pena <felipe@php.net> | 2012-03-11 15:42:57 +0000 |
---|---|---|
committer | Felipe Pena <felipe@php.net> | 2012-03-11 15:42:57 +0000 |
commit | af2fc625df1e05f712211f7c23d00120cbac731f (patch) | |
tree | ef7c8b7248c54666606f8e65388b48b47201f618 /ext | |
parent | eac33b454c2b3762a2f8f5fa679170adbab62c59 (diff) | |
download | php-git-af2fc625df1e05f712211f7c23d00120cbac731f.tar.gz |
- Fixed memory leak when calling SplFileInfo's constructor twice
Diffstat (limited to 'ext')
-rwxr-xr-x | ext/spl/spl_directory.c | 9 | ||||
-rw-r--r-- | ext/spl/tests/SplFileInfo_001.phpt | 11 |
2 files changed, 19 insertions, 1 deletions
diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index 01b994b9c3..f0e903f0bf 100755 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -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 index 0000000000..72060f0dba --- /dev/null +++ b/ext/spl/tests/SplFileInfo_001.phpt @@ -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! |