Bug #76946 [Ana->Csd]: Cyclic reference in generator not detected
| From: | nikic@php.net | Date: | Fri, 28 Sep 2018 17:19:32 +0000 |
| Subject: | Bug #76946 [Ana->Csd]: Cyclic reference in generator not detected | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-217274@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: Analyzed
+Status: Closed
Type: Bug
Package: Reproducible crash
Operating System: Alpine
PHP Version: 7.2.10
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=83e2b9e2202da6cc25bdaac67a58022b90be88e7
Log: Fixed bug #76946
Previous Comments:
------------------------------------------------------------------------
[2018-09-28 16:27:04] nikic@php.net
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 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