Skip to content

Commit 3de0ccf

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fix GH-8366: ArrayIterator may leak when calling __construct()
2 parents 8de75fa + 549cf3a commit 3de0ccf

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

ext/spl/spl_array.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,10 @@ static void spl_array_set_array(zval *object, spl_array_object *intern, zval *ar
10361036

10371037
intern->ar_flags &= ~SPL_ARRAY_IS_SELF & ~SPL_ARRAY_USE_OTHER;
10381038
intern->ar_flags |= ar_flags;
1039-
intern->ht_iter = (uint32_t)-1;
1039+
if (intern->ht_iter != (uint32_t)-1) {
1040+
zend_hash_iterator_del(intern->ht_iter);
1041+
intern->ht_iter = (uint32_t)-1;
1042+
}
10401043
}
10411044
/* }}} */
10421045

ext/spl/tests/gh8366.phpt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--TEST--
2+
Bug GH-8366 (ArrayIterator may leak when calling __construct())
3+
--FILE--
4+
<?php
5+
$it = new \ArrayIterator();
6+
foreach ($it as $elt) {}
7+
$it->__construct([]);
8+
?>
9+
--EXPECT--

0 commit comments

Comments
 (0)