Skip to content

Generator memory leak when interrupted during argument evaluation #9750

Closed

Description

@arnaud-lb

Description

Found while looking at #9735

The following code:

<?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 24c2970

Operating System

No response

Activity

  1. self-assigned this
    on Oct 15, 2022
  2. changed the title [-]Generator memory leak when interrupted while the generator is on the stack [/-] [+]Generator memory leak when interrupted during argument evaluation[/+] on Oct 15, 2022
  3. arnaud-lb commented on Nov 5, 2022

    @arnaud-lb
    MemberAuthor

    Fixed in #9756

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions