|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76946 Cyclic reference in generator not detected
Submitted: 2018-09-28 16:16 UTC Modified: 2018-09-28 16:27 UTC
From: sam at mousa dot nl Assigned:
Status: Closed Package: Reproducible crash
PHP Version: 7.2.10 OS: Alpine
Private report: No CVE-ID: None
 [2018-09-28 16:16 UTC] sam at mousa dot nl
When a specifically structured cyclic reference is created the garbage collector fails to detect it which causes the references to never be freed. This leads to a memory leak.

Test script:

Expected result:
I'd expect it to never run out of memory; it repeatedly calls a closure that:
- Does not access globals
- Creates an object that goes out of scope

Actual result:
The instances created by the closure never get destroyed, even when explicitly calling gc_collect_cycles. 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-09-28 16:19 UTC] sam at mousa dot nl
Running this in phpdbg and then checking the active generators shows they are still active:

#1418556: Trapper::getYield(ref=stdClass) at /projects/bug-sample/nodatabase.php:14
#1418558: Trapper::getYield(ref=stdClass) at /projects/bug-sample/nodatabase.php:14
#1418560: Trapper::getYield(ref=stdClass) at /projects/bug-sample/nodatabase.php:14
#1418562: Trapper::getYield(ref=stdClass) at /projects/bug-sample/nodatabase.php:14
 [2018-09-28 16:27 UTC]
-Status: Open +Status: Analyzed
 [2018-09-28 16:27 UTC]
This is because we don't include live vars in generator GC. This was originally left out because it only matters in few situations while being somewhat risky. I guess we'll have to add support for it now...
 [2018-09-28 17:19 UTC]
Automatic comment on behalf of
Log: Fixed bug #76946
 [2018-09-28 17:19 UTC]
-Status: Analyzed +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jul 19 16:01:30 2024 UTC