Bug #80199 [NEW]: PHP leaking memory by not releasing anonymous function declaration

From: Date: Wed, 07 Oct 2020 17:48:36 +0000
Subject: Bug #80199 [NEW]: PHP leaking memory by not releasing anonymous function declaration
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-229455@lists.php.net to get a copy of this message
From: gilperon at gmail dot com Operating system: CENTOS 8 and WINDOWS 10 PHP version: 7.4.11 Package: *General Issues Bug Type: Bug Bug description:PHP leaking memory by not releasing anonymous function declaration Description: ------------ Run the test script. In it I am declaring an anonymous function (because I want to be able to unset it later) using eval (my actual function is much more complicated, and I really need to use eval) and unseting it. If you check memory usage while executing this script you will see it will rise, rise and crash. What is weird, is that if I execute the same test script but without using eval (code below) it works just fine, no memory leak, no crash... nothing. Apache barely uses any memory. <?php set_time_limit(0); ini_set('memory_limit','-1'); $aaa = array(); for ($i=0;$i<10000000;$i++) { $aaa[$i] = function($iduc,$cp_ccp) { return ($cp_ccp and $iduc); }; unset($aaa[$i]); } ?> Test script: --------------- <?php set_time_limit(0); ini_set('memory_limit','-1'); $a = array(); for ($i=0;$i<100000000;$i++) { eval(' $a[' . $i . '] = function($i,$da_ca,$iduc,$cp_ccp) { return ($cp_ccp[' . $i . '] and $iduc[' . ($i+1) . ']); }; '); unset($funcao_testar_retorno_parametros[$i]); } ?> Expected result: ---------------- Variable should be unsetted and memory released. Actual result: -------------- Variable does not get out of memory and in a couple minutes crash Apache with lots of error messages complaining about lack of system memory on error_log. -- Edit bug report at https://bugs.php.net/bug.php?id=80199&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=80199&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=80199&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=80199&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=80199&r=needscript Try newer version: https://bugs.php.net/fix.php?id=80199&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=80199&r=support Expected behavior: https://bugs.php.net/fix.php?id=80199&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=80199&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=80199&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=80199&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=80199&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=80199&r=dst IIS Stability: https://bugs.php.net/fix.php?id=80199&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=80199&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=80199&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=80199&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=80199&r=mysqlcfg

« previous php.bugs (#229455) next »