From: mario at mariomedina dot net
Operating system: Linux
PHP version: 5.0.0
PHP Bug Type: Reproducible crash
Bug description: popen memory leak
Description:
------------
When you open a pipe with popen, work with it an then close, some bytes
aren't freed, so when you do that task a lot of times you get out of
memory error, (with memory limit) and php crash.... It is working with php
cgi mode... I tested it on php 4.x, and 5.0.0...
When you do proc_open is the same.
When you open a popen and it fails then no memory leak exists.
Reproduce code:
---------------
<?
printlog("Iniciando");
for($i=0;$i<10;$i++) {
if(($fp=popen("ls","r"))==true) {
printlog("Abierto");
while(!feof($fp))
$l=fgets($fp, 8192);
printlog("Leido");
fflush($fp);
pclose($fp);
printlog("Cerrado");
unset($fp);
unset($l);
printlog("Liberado");
sleep(1);
}
}
printlog("Terminando");
die();
function printlog($src) {
printf("%s (%.03fkb): %s\n",date("r"), memory_get_usage()/1024,
rtrim($src));
}
?>
Expected result:
----------------
I expect that when pipe was closed all the memory is freed.
Actual result:
--------------
There are memory leak for about 200 bytes
--
Edit bug report at http://bugs.php.net/?id=29511&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=29511&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=29511&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=29511&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=29511&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=29511&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=29511&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=29511&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=29511&r=support
Expected behavior: http://bugs.php.net/fix.php?id=29511&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=29511&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=29511&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=29511&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=29511&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=29511&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=29511&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=29511&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=29511&r=float