php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81361 memory leak with anonymous function in an eval statement
Submitted: 2021-08-14 22:36 UTC Modified: 2021-08-16 10:21 UTC
From: zelnaga at gmail dot com Assigned:
Status: Duplicate Package: Performance problem
PHP Version: 8.0.9 OS: any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: zelnaga at gmail dot com
New email:
PHP Version: OS:

 

 [2021-08-14 22:36 UTC] zelnaga at gmail dot com
Description:
------------
eval('return function() {};') seems to create a memory leak.

If I replace eval('return function() {};'); with function() {}; there's no memory leak but if I replace eval('return function() {};'); with $a = eval('return function() {};'); unset($a); there is still. So it's like the eval() is what's causing the issue.

Per https://3v4l.org/3p4sl apparently this code didn't start leaking until PHP 7.4.

Test script:
---------------
<?php
while (true) {
    eval('return function() {};');
    gc_collect_cycles();
    $new = memory_get_usage();
    if (isset($old)) {
        echo ($new - $old) . "\n";
    }
    $old = $new;
}
?>

Expected result:
----------------
I would expect this to output a bunch of 0's, one after the other.

Actual result:
--------------
432 is output over and over and over again, indicating that each new pass is consuming an additional 432 bytes than the last one.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-08-16 10:21 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 [2021-08-16 10:21 UTC] nikic@php.net
Duplicate of bug #76982.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Oct 28 17:03:35 2021 UTC