Bug #81361 [NEW]: memory leak with anonymous function in an eval statement
| From: | zelnaga at gmail dot com | Date: | Sat, 14 Aug 2021 22:36:30 +0000 |
| Subject: | Bug #81361 [NEW]: memory leak with anonymous function in an eval statement | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-235816@lists.php.net to get a copy of this message | ||
From: zelnaga at gmail dot com
Operating system: any
PHP version: 8.0.9
Package: Performance problem
Bug Type: Bug
Bug description:memory leak with anonymous function in an eval statement
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.
--
Edit bug report at https://bugs.php.net/bug.php?id=81361&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=81361&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=81361&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=81361&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=81361&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=81361&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=81361&r=support
Expected behavior: https://bugs.php.net/fix.php?id=81361&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=81361&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=81361&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=81361&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81361&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=81361&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=81361&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=81361&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=81361&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=81361&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=81361&r=mysqlcfg