Bug #50480 [Com]: memory leak with eval()

From: Date: Tue, 17 Nov 2015 14:10:44 +0000
Subject: Bug #50480 [Com]: memory leak with eval()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-197296@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=50480&edit=1

 ID:                 50480
 Comment by:         chris at willowsconsulting dot ie
 Reported by:        lesjno at free dot fr
 Summary:            memory leak with eval()
 Status:             No Feedback
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   *
 PHP Version:        5.3.1
 Block user comment: N
 Private report:     N

 New Comment:

I became interested by the eval() behavior recently, and I can confirm that the memory usage gets
higher by the time of the execution.
However it is not really a bug, but the way eval() is fundamentally written:
* it creates a temp file with the code inside (sometimes it is stored in memory)
* it then includes that temp file using a normal include() function

As you can see, the more eval() you do, the more include() it will trigger, resulting in a memory
usage that cannot be freed...


Previous Comments:
------------------------------------------------------------------------
[2013-02-18 00:34:03] php-bugs at lists dot php dot net

No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.

------------------------------------------------------------------------
[2011-11-16 13:58:09] felipe@php.net

Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/



------------------------------------------------------------------------
[2011-09-12 19:54:19] horsarias at hotmail dot com

Hi, my php console process reaches the memory limit after some days of hard work but the only
suspect that i find in de code is the "eval". using linux with php 5.3.6  ( in my code,
the eval function is HEAVALY usted with HEAVY arrays being evaluated)

Bye

------------------------------------------------------------------------
[2010-05-27 13:26:46] letssurf at gmail dot com

PHP Versions:
-------------
Tested as broken with
5.2.6
5.3.2

Reproduce code:
---------------

<?php
// working code, runs for ever
$code = 'return false;';
while(true) {
   $result = eval($code);
   $mem = memory_get_peak_usage(true);
   var_dump($result, $mem);
}

<?php
// broken code, dies due to memory limit being reached
$code = 'some invalid php code';
while(true) {
   $result = eval($code);
   $mem = memory_get_peak_usage(true);
   var_dump($result, $mem);
}


Expected result:
----------------
A var_dump of false and the peak memory usage, not increasing.


Actual result:
--------------
A var_dump of false and the peak memory usage keeps increasing.

------------------------------------------------------------------------
[2010-04-26 10:09:45] lesjno at free dot fr

I've just tried the PHP 5.3.2 release but the memory leak remains.
The test script is the following :
CODE :
------
$status="";
$ch="\$result=true;";  // a chain with a good php syntax
$memory_used1 = memory_get_usage();
$status = @eval($ch) ;
$memory_used2 = memory_get_usage();
echo "chain to eval : \"$ch\" ==> status = ";
var_dump($status);
echo "<BR>";
echo "<b>memory difference =
".($memory_used2-$memory_used1)."<BR><BR></b>\n";

$ch="abcdef";   // a chain with a bad php syntaxe
$memory_used1 = memory_get_usage();
$status = @eval($ch) ;
$memory_used2 = memory_get_usage();
echo "chain to eval : \"$ch\" ==> status = ";
var_dump($status);
echo "<BR>";
echo "<b>memory difference =
".($memory_used2-$memory_used1)."<BR></b>\n";

Actual result:
--------------
chain to eval : "$result=true;" ==> status = NULL
memory difference = 512

chain to eval : "abcdef" ==> status = bool(false)
memory difference = 8632


Expected result:
--------------
chain to eval : "$result=true;" ==> status = NULL
memory difference = 0

chain to eval : "abcdef" ==> status = bool(false)
memory difference = 0

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=50480


--
Edit this bug report at https://bugs.php.net/bug.php?id=50480&edit=1


Thread (10 messages)

« previous php.bugs (#197296) next »