diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index e5d97141684..db9a4f6f6b3 100644 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -1036,7 +1036,10 @@ static void spl_array_set_array(zval *object, spl_array_object *intern, zval *ar intern->ar_flags &= ~SPL_ARRAY_IS_SELF & ~SPL_ARRAY_USE_OTHER; intern->ar_flags |= ar_flags; - intern->ht_iter = (uint32_t)-1; + if (intern->ht_iter != (uint32_t)-1) { + zend_hash_iterator_del(intern->ht_iter); + intern->ht_iter = (uint32_t)-1; + } } /* }}} */ diff --git a/ext/spl/tests/gh8366.phpt b/ext/spl/tests/gh8366.phpt new file mode 100644 index 00000000000..1da5360cc96 --- /dev/null +++ b/ext/spl/tests/gh8366.phpt @@ -0,0 +1,9 @@ +--TEST-- +Bug GH-8366 (ArrayIterator may leak when calling __construct()) +--FILE-- +__construct([]); +?> +--EXPECT--