php-src/Zend/tests/gh7958.phpt
Christoph M. Becker fb70460d8e
Fix GH-7958: Nested CallbackFilterIterator is leaking memory
We implement `zend_object_iterator_funcs.get_gc` for user iterators to
avoid the memory leak.

Closes GH-8107.
2022-02-21 12:39:07 +01:00

44 lines
803 B
PHP

--TEST--
GH-7958 (Nested CallbackFilterIterator is leaking memory)
--FILE--
<?php
class Action
{
public \Iterator $iterator;
public function __construct(array $data)
{
$this->iterator = new ArrayIterator($data);
echo '-- c ' . spl_object_id($this) . "\n";
}
public function __destruct()
{
echo '-- d ' . spl_object_id($this) . "\n";
}
public function filter()
{
$this->iterator = new \CallbackFilterIterator($this->iterator, fn() => true);
$this->iterator->rewind();
}
}
$action = new Action(['a', 'b']);
$action->filter();
$action->filter();
print_r(iterator_to_array($action->iterator));
$action = null;
gc_collect_cycles();
echo "==DONE==\n";
?>
--EXPECT--
-- c 1
Array
(
[0] => a
[1] => b
)
-- d 1
==DONE==