Skip to content

Commit 549cf3a

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix GH-8366: ArrayIterator may leak when calling __construct()
2 parents ec0771c + 1762a87 commit 549cf3a

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ PHP NEWS
2626
. Fixed bug GH-8267 (MySQLi uses unsupported format specifier on Windows).
2727
(cmb)
2828

29+
- SPL:
30+
. Fixed bug GH-8366 (ArrayIterator may leak when calling __construct()).
31+
(cmb)
32+
2933
- Streams:
3034
. Fixed php://temp does not preserve file-position when switched to temporary
3135
file. (Bernd Holzmüller)

ext/spl/spl_array.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,10 @@ static void spl_array_set_array(zval *object, spl_array_object *intern, zval *ar
10881088

10891089
intern->ar_flags &= ~SPL_ARRAY_IS_SELF & ~SPL_ARRAY_USE_OTHER;
10901090
intern->ar_flags |= ar_flags;
1091-
intern->ht_iter = (uint32_t)-1;
1091+
if (intern->ht_iter != (uint32_t)-1) {
1092+
zend_hash_iterator_del(intern->ht_iter);
1093+
intern->ht_iter = (uint32_t)-1;
1094+
}
10921095
}
10931096
/* }}} */
10941097

ext/spl/tests/gh8366.phpt

+9
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)