Skip to content

Commit 80cb6e5

Browse files
committed
- Fixed memory leak when calling SplFileInfo's constructor twice
1 parent b7ae5e0 commit 80cb6e5

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

ext/spl/spl_directory.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,10 @@ static zend_object_value spl_filesystem_object_clone(zval *zobject TSRMLS_DC)
376376
void spl_filesystem_info_set_filename(spl_filesystem_object *intern, char *path, int len, int use_copy TSRMLS_DC) /* {{{ */
377377
{
378378
char *p1, *p2;
379+
380+
if (intern->file_name) {
381+
efree(intern->file_name);
382+
}
379383

380384
intern->file_name = use_copy ? estrndup(path, len) : path;
381385
intern->file_name_len = len;
@@ -396,7 +400,10 @@ void spl_filesystem_info_set_filename(spl_filesystem_object *intern, char *path,
396400
} else {
397401
intern->_path_len = 0;
398402
}
399-
403+
404+
if (intern->_path) {
405+
efree(intern->_path);
406+
}
400407
intern->_path = estrndup(path, intern->_path_len);
401408
} /* }}} */
402409

ext/spl/tests/SplFileInfo_001.phpt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
Testing SplFileInfo calling the constructor twice
3+
--FILE--
4+
<?php
5+
$x = new splfileinfo(1);
6+
$x->__construct(1);
7+
8+
echo "done!\n";
9+
?>
10+
--EXPECT--
11+
done!

0 commit comments

Comments
 (0)