Bug #80777 [Opn->Dup]: Memory Leak on function() in include

From: Date: Fri, 19 Feb 2021 17:16:06 +0000
Subject: Bug #80777 [Opn->Dup]: Memory Leak on function() in include
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-232288@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80777&edit=1

 ID:                 80777
 Updated by:         nikic@php.net
 Reported by:        php dot net at mailt dot so
 Summary:            Memory Leak on function() in include
-Status:             Open
+Status:             Duplicate
 Type:               Bug
 Package:            opcache
 Operating System:   Any/Debian
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

Duplicate of bug #76982.


Previous Comments:
------------------------------------------------------------------------
[2021-02-19 17:07:51] php dot net at mailt dot so

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 this bug report at https://bugs.php.net/bug.php?id=80777&edit=1


Thread (2 messages)

« previous php.bugs (#232288) next »