From: romain dot riviere at gmail dot com Operating system: Gentoo Linux 32bit PHP version: 5.2.10 PHP Bug Type: *General Issues Bug description: Memory leak ending up in Out of Memory errors
Description: ------------ While trying to diagnose apparently random Out of Memory errors in various PHP scripts (including Drupal among others), I ended up using the code pasted below for testing purposes. Browing the resulting page several times always results in an ever-increasing VSZ for apache processes (up to 4GB in my case) and eventually Out of Memory errors way before the script itself actually reaches the limit. The script was called with size=61 in my case (memory_limit=64M). On an 8GB system, it might take as many as 30 requests to recreate the bug. With a higher memory limit and value of the "size" parameter, it will probably happen much sooner. PHP compiled with Reproduce code: --------------- <?php ini_set('display_errors',true); if (isset($_GET['size']) && $_GET['size'] < 200) { $mb = intval($_GET['size']); } else { $mb=5; } $var = ''; echo 'Memory limit: '.ini_get('memory_limit').'<br>'; for ($i=0; $i<=$mb; $i++) { $var.= str_repeat('a',1*1024*1024); echo memory_get_usage().'<br>'; } echo 'String length: '. strlen($var); ?> Expected result: ---------------- For the first few runs, the script correctly displays the memory usage and the value is consistent with the memory limit : Memory limit: 64M <snip> String length: 65011712 Actual result: -------------- Memory limit: 64M <snip> Fatal error: Out of memory (allocated 61341696) at /var/tmp/portage/dev-lang/php-5.2.10/work/php-5.2.10/ext/standard/string.c:4599 (tried to allocate 1048577 bytes) in /home/acrm/OF-svn/2.0/test.php on line 14 Subsequent runs : Fatal error: Out of memory (allocated 262144) at /var/tmp/portage/dev-lang/php-5.2.10/work/php-5.2.10/ext/standard/string.c:4599 (tried to allocate 1048577 bytes) in /home/acrm/OF-svn/2.0/test.php on line 14 -- Edit bug report at http://bugs.php.net/?id=49501&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=49501&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=49501&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=49501&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=49501&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=49501&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=49501&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=49501&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=49501&r=needscript Try newer version: http://bugs.php.net/fix.php?id=49501&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=49501&r=support Expected behavior: http://bugs.php.net/fix.php?id=49501&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=49501&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=49501&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=49501&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49501&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=49501&r=dst IIS Stability: http://bugs.php.net/fix.php?id=49501&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=49501&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=49501&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=49501&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=49501&r=mysqlcfg