ID: 49501
Updated by: [email protected]
Reported By: romain dot riviere at gmail dot com
Status: Open
Bug Type: *General Issues
Operating System: Gentoo Linux 32bit
PHP Version: 5.2.10
New Comment:
Are you saying you don't see it if you don't use --with-pic?
And I am curious, why do you want pic? libphp5.so isn't a
general-purpose shared library that can be linked into many different
things. It is a very targeted library compiled for a specific binary to
link and as such compiling it pic just adds unnecessary overhead.
Previous Comments:
------------------------------------------------------------------------
[2009-09-08 20:42:30] romain dot riviere at gmail dot com
The last line of the initial description should have read : PHP
compiled --with-pic.
For the record, the problem appeared in Drupal and was reported as
happening at zend_opcode.c:48. However, since it can obviously be
reproduced with something as simple as a string, I believe it is a more
general memory leak issue.
------------------------------------------------------------------------
[2009-09-08 19:04:48] romain dot riviere at gmail dot com
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 this bug report at http://bugs.php.net/?id=49501&edit=1