[php-src] Issue #9750: Generator memory leak when interrupted while the generator is on the stack
| From: | arnaud-lb | Date: | Fri, 14 Oct 2022 14:04:43 +0000 |
| Subject: | [php-src] Issue #9750: Generator memory leak when interrupted while the generator is on the stack | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-242596@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/9750
Author: arnaud-lb
### Description
Found while looking at #9735
The following code:
```php
<?php
function f() {
}
$gen = function () use (&$gen) {
f($gen, yield);
};
$gen = $gen();
foreach ($gen as $value) {
break;
}
$gen = null;
gc_collect_cycles();
```
Resulted in this output:
```
[Fri Oct 14 15:51:40 2022] Script: 'gen.php'
Zend/zend_generators.c(409) : Freeing 0x00007fb3a365d3c0 (272 bytes), script=gen.php
=== Total 1 memory leaks detected ===
```
But I expected this output instead:
```
```
### PHP Version
PHP 8.1 24c297086d01811c5fd14ba3a3b9151759ab9c16
### Operating System
_No response_