php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35891 Erroneous code thru eval() causes memory leak
Submitted: 2006-01-04 13:53 UTC Modified: 2006-01-04 15:00 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:1 (33.3%)
From: taneli at crasman dot fi Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: 5.1.1, 4.4.1 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: taneli at crasman dot fi
New email:
PHP Version: OS:

 

 [2006-01-04 13:53 UTC] taneli at crasman dot fi
Description:
------------
Running unparsable code - which shouldn't be done, of course, but - causes a memory leak. Proper, parsable code does not cause memory leaks.

Reproduce code:
---------------
<?{
  echo "Erroneous code eval():\n";
  echo "Memory used before: " . memory_get_usage() . "\n";
  for ($i = 0; $i < 1000; $i++)
  {
    eval('$foo = 1; $bar = 2; asdf');
    echo "Loop $i, memory used: " . memory_get_usage() . "\n";
  }
  echo "Memory used after: " . memory_get_usage() . "\n";

  echo "\nProper code eval():\n";
  echo "Memory used before: " . memory_get_usage() . "\n";
  for ($i = 0; $i < 1000; $i++)
  {
    eval('$foo = 1; $bar = 2;');
    echo "Loop $i, memory used: " . memory_get_usage() . "\n";
  }
  echo "Memory used after: " . memory_get_usage() . "\n";


}?>


Expected result:
----------------
Erroneous code eval():
Memory used before: 42568
Loop 1, memory used: 42568
...
Loop 999, memory used: 42568
Memory used after: 42568

Proper code eval():
Memory used before: 42568
Loop 1, memory used: 42568
...
Loop 999, memory used: 42568
Memory used after: 42568



Actual result:
--------------
Erroneous code eval():
Memory used before: 42568
Loop 0, memory used: 49960
Loop 1, memory used: 57040
Loop 2, memory used: 64088
Loop 3, memory used: 71136
...
Loop 999, memory used: 7073088
Memory used after: 7073064

Proper code eval():
Memory used before: 7073064
Loop 0, memory used: 7073376
...
Loop 999, memory used: 7073376
Memory used after: 7073352


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-01-04 13:59 UTC] taneli at crasman dot fi
Also present in PHP 4.4.1.

BTW: Worst CAPTCHA images, ever.
 [2006-01-04 14:51 UTC] tony2001@php.net
This is expected.
After parse error (wherever it happens) the engine is in unstable state and is unable to gracefully free all the memory allocated before.
Just don't do it [tm].
 [2006-01-04 14:58 UTC] taneli at crasman dot fi
That would be just fine if there was a method to check PHP's syntax (other than "php -l") and/or the entire script would terminate properly (the script continues to run even if eval()'ed code contains a parse error).

Of course, I don't see why a *parse* error should leave any engine to an unstable state. Apparently this is reason why user error handlers were disabled for the more serious errors?
 [2006-01-04 15:00 UTC] taneli at crasman dot fi
There used to be a php_check_syntax() function, but it only accepted files and insisted on executing the specified file.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 21:01:36 2024 UTC