|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78589 Memory leak with GC + __destruct()
Submitted: 2019-09-23 10:20 UTC Modified: 2019-09-23 10:35 UTC
From: Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 7.4Git-2019-09-23 (Git) OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
39 - 3 = ?
Subscribe to this entry?

 [2019-09-23 10:20 UTC]
This is reduced from an OSS-Fuzz testcase involving unserialize(), but turns out to be some kind of generic GC bug. It is related to the changes to __destruct() handling in 7.4.

Test script:
class Test {
    public function __destruct() {} 
$test = new Test; 
$test->foo = [&$test->foo];
$ary = [&$ary, $test];
unset($ary, $test);

Actual result:
[Mon Sep 23 12:17:48 2019]  Script:  '/home/nikic/php-src-fuzz/t009.php'
Zend/zend_vm_execute.h(27609) :  Freeing 0x00007f8220201940 (32 bytes), script=/home/nikic/php-src-fuzz/t009.php
[Mon Sep 23 12:17:48 2019]  Script:  '/home/nikic/php-src-fuzz/t009.php'
/home/nikic/php-src-fuzz/Zend/zend_hash.c(256) :  Freeing 0x00007f82202588a0 (56 bytes), script=/home/nikic/php-src-fuzz/t009.php
[Mon Sep 23 12:17:48 2019]  Script:  '/home/nikic/php-src-fuzz/t009.php'
/home/nikic/php-src-fuzz/Zend/zend_hash.c(131) :  Freeing 0x00007f822025c280 (264 bytes), script=/home/nikic/php-src-fuzz/t009.php
=== Total 3 memory leaks detected ===


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-09-23 10:35 UTC]
-Status: Open +Status: Analyzed
 [2019-09-23 10:35 UTC]
The problem seems to be that we set gc_protected=1 during the zval destruction phase. However, in this case the destruction of the object wants to add the inner array to the GC buffer. (It was previously removed as nested data of the __destruct object.)
 [2019-09-24 10:19 UTC]
Automatic comment on behalf of
Log: Fixed bug #78589
 [2019-09-24 10:19 UTC]
-Status: Analyzed +Status: Closed
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Oct 29 17:01:24 2020 UTC