Skip to content

Commit 549235d

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Fix leak when breaking out of FilesystemIterator Fixed bug #80600
2 parents 15f713b + 8e9eeca commit 549235d

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
@@ -1633,15 +1633,7 @@ zend_object_iterator *spl_filesystem_dir_get_iterator(zend_class_entry *ce, zval
16331633
static void spl_filesystem_dir_it_dtor(zend_object_iterator *iter)
16341634
{
16351635
spl_filesystem_iterator *iterator = (spl_filesystem_iterator *)iter;
1636-
1637-
if (!Z_ISUNDEF(iterator->intern.data)) {
1638-
zval *object = &iterator->intern.data;
1639-
zval_ptr_dtor(object);
1640-
}
1641-
/* Otherwise we were called from the owning object free storage handler as
1642-
* it sets iterator->intern.data to IS_UNDEF.
1643-
* We don't even need to destroy iterator->current as we didn't add a
1644-
* reference to it in move_forward or get_iterator */
1636+
zval_ptr_dtor(&iterator->intern.data);
16451637
}
16461638
/* }}} */
16471639

@@ -1703,16 +1695,8 @@ static void spl_filesystem_dir_it_rewind(zend_object_iterator *iter)
17031695
static void spl_filesystem_tree_it_dtor(zend_object_iterator *iter)
17041696
{
17051697
spl_filesystem_iterator *iterator = (spl_filesystem_iterator *)iter;
1706-
1707-
if (!Z_ISUNDEF(iterator->intern.data)) {
1708-
zval *object = &iterator->intern.data;
1709-
zval_ptr_dtor(object);
1710-
} else {
1711-
if (!Z_ISUNDEF(iterator->current)) {
1712-
zval_ptr_dtor(&iterator->current);
1713-
ZVAL_UNDEF(&iterator->current);
1714-
}
1715-
}
1698+
zval_ptr_dtor(&iterator->intern.data);
1699+
zval_ptr_dtor(&iterator->current);
17161700
}
17171701
/* }}} */
17181702

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)