php.net |  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
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. 

Patches

Pull Requests

History

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] nikic@php.net
-Status: Open +Status: Analyzed
 [2018-09-28 16:27 UTC] 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 17:19 UTC] nikic@php.net
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
 [2018-09-28 17:19 UTC] nikic@php.net
-Status: Analyzed +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 08:01:29 2024 UTC