Skip to content

Commit 8e9eeca

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix leak when breaking out of FilesystemIterator
2 parents 6ec25f3 + 44a80b6 commit 8e9eeca

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

ext/spl/spl_directory.c

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,15 +1643,7 @@ zend_object_iterator *spl_filesystem_dir_get_iterator(zend_class_entry *ce, zval
16431643
static void spl_filesystem_dir_it_dtor(zend_object_iterator *iter)
16441644
{
16451645
spl_filesystem_iterator *iterator = (spl_filesystem_iterator *)iter;
1646-
1647-
if (!Z_ISUNDEF(iterator->intern.data)) {
1648-
zval *object = &iterator->intern.data;
1649-
zval_ptr_dtor(object);
1650-
}
1651-
/* Otherwise we were called from the owning object free storage handler as
1652-
* it sets iterator->intern.data to IS_UNDEF.
1653-
* We don't even need to destroy iterator->current as we didn't add a
1654-
* reference to it in move_forward or get_iterator */
1646+
zval_ptr_dtor(&iterator->intern.data);
16551647
}
16561648
/* }}} */
16571649

@@ -1713,16 +1705,8 @@ static void spl_filesystem_dir_it_rewind(zend_object_iterator *iter)
17131705
static void spl_filesystem_tree_it_dtor(zend_object_iterator *iter)
17141706
{
17151707
spl_filesystem_iterator *iterator = (spl_filesystem_iterator *)iter;
1716-
1717-
if (!Z_ISUNDEF(iterator->intern.data)) {
1718-
zval *object = &iterator->intern.data;
1719-
zval_ptr_dtor(object);
1720-
} else {
1721-
if (!Z_ISUNDEF(iterator->current)) {
1722-
zval_ptr_dtor(&iterator->current);
1723-
ZVAL_UNDEF(&iterator->current);
1724-
}
1725-
}
1708+
zval_ptr_dtor(&iterator->intern.data);
1709+
zval_ptr_dtor(&iterator->current);
17261710
}
17271711
/* }}} */
17281712

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Don't leak when breaking from FilesystemIterator
3+
--FILE--
4+
<?php
5+
$iterator = new FilesystemIterator(__DIR__);
6+
foreach ($iterator as $value) {
7+
break;
8+
}
9+
?>
10+
===DONE===
11+
--EXPECT--
12+
===DONE===

0 commit comments

Comments
 (0)