Bug #80777 [NEW]: Memory Leak on function() in include

From: Date: Fri, 19 Feb 2021 17:07:51 +0000
Subject: Bug #80777 [NEW]: Memory Leak on function() in include
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-232287@lists.php.net to get a copy of this message
From: php dot net at mailt dot so Operating system: Any/Debian PHP version: Irrelevant Package: opcache Bug Type: Bug Bug description:Memory Leak on function() in include Description: ------------ Earliest tested version: 7.3.7, also tested: 7.4.15 (Debian package) 8.0.2 (Compiled from src) Propably all versions affected. Defining a function in an include file seems to break/disable some kind of cache cleaning and results in a memory leak. In most cases this might not hurt, since it only occurs once. I found this on an run-time editable script where the include file gets reloaded on every loop and after years of using it this way, it suddently broke and instead of a few kbyte of ram it crashed after a day reaching the 125mb limit. After searching and fiddling with the prior changes i made i reduced the code to a minimal test for this specific problem. Test script: --------------- main.php: <?php function checkmem($name = "") { global $oldmem; $newmem = memory_get_usage(false); if ($newmem > $oldmem) { echo "\n".$oldmem." -> ".$newmem." (".($newmem-$oldmem).") Checkpoint $name\n"; $oldmem = $newmem; } } while (!usleep(10000)) { checkmem("Preinclude"); include("inc.php"); checkmem("Postinclude"); } ?> inc.php: <?php checkmem("inner begin"); if (1 == 0) function test() {} checkmem("inner end"); ?> Expected result: ---------------- The memory size shouldn't increase unlimited (The code is never reached, the include is left successfully, etc..) The result is the same whether or not the function exists. Actual result: -------------- php main.php -> 394136 (394136) Checkpoint Preinclude 394136 -> 395256 (1120) Checkpoint inner begin 395256 -> 460792 (65536) Checkpoint inner begin 460792 -> 526328 (65536) Checkpoint inner begin 526328 -> 591864 (65536) Checkpoint inner begin .... until OOM Just re-including a file unlimited times is no problem until a user defined function is declared within. Then some kind of optimization seems to fail and the used memory get's bigger and bigger. Without the user defined function definition in the include, the memory amount is almost unchanged even when the file is changed during runtime (and reincluded ...) -- Edit bug report at https://bugs.php.net/bug.php?id=80777&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=80777&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=80777&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=80777&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=80777&r=needscript Try newer version: https://bugs.php.net/fix.php?id=80777&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=80777&r=support Expected behavior: https://bugs.php.net/fix.php?id=80777&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=80777&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=80777&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=80777&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=80777&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=80777&r=dst IIS Stability: https://bugs.php.net/fix.php?id=80777&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=80777&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=80777&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=80777&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=80777&r=mysqlcfg

« previous php.bugs (#232287) next »