From 80cb6e56f61b00791169aeb6b018eee5d27bc848 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sun, 11 Mar 2012 15:42:57 +0000 Subject: [PATCH] - Fixed memory leak when calling SplFileInfo's constructor twice --- ext/spl/spl_directory.c | 9 ++++++++- ext/spl/tests/SplFileInfo_001.phpt | 11 +++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 ext/spl/tests/SplFileInfo_001.phpt diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index 4b0f48fedd..a7bbf26159 100755 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -376,6 +376,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; @@ -396,7 +400,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-- +__construct(1); + +echo "done!\n"; +?> +--EXPECT-- +done! -- 2.40.0