php-src/Zend/tests/generators/no_foreach_var_leaks.phpt
Nikita Popov 64a643a4e3 Free loop variables
If the generator is closed before it has finished running, it may happen
that some FREE or SWITCH_FREE opcodes haven't been executed and memory is
leaked.

This fixes it by walking the brk_cont_array and manually freeing the
variables.
2012-05-27 17:14:20 +02:00

20 lines
316 B
PHP

--TEST--
foreach() (and other) variables aren't leaked on premature close
--FILE--
<?php
function *gen(array $array) {
foreach ($array as $value) {
yield $value;
}
}
$gen = gen(['Foo', 'Bar']);
var_dump($gen->current());
// generator is closed here, without running SWITCH_FREE
?>
--EXPECT--
string(3) "Foo"