Bug #76946 [Opn->Ana]: Cyclic reference in generator not detected

From: Date: Fri, 28 Sep 2018 16:27:04 +0000
Subject: Bug #76946 [Opn->Ana]: Cyclic reference in generator not detected
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-217273@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76946&edit=1 ID: 76946 Updated by: nikic@php.net Reported by: sam at mousa dot nl Summary: Cyclic reference in generator not detected -Status: Open +Status: Analyzed Type: Bug Package: Reproducible crash Operating System: Alpine PHP Version: 7.2.10 Block user comment: N Private report: N New Comment: 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... Previous Comments: ------------------------------------------------------------------------ [2018-09-28 16:19:27] 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:16:29] sam at mousa dot nl Description: ------------ 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: --------------- https://github.com/SamMousa/yii2-bug-sample/blob/master/nodatabase.php 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. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76946&edit=1

« previous php.bugs (#217273) next »