From: jim-bo at hotpop dot com Operating system: Linux Debian Etch PHP version: 5.1.6 PHP Bug Type: CGI related Bug description: memory leak in fgets when using cli
Description: ------------ Using cli on debian etch it seems that fgets leaks memory. I have replaced fgets with stream_get_line and it seems to not leak. Please forgive me if this is a programming error on my behalf...but i can't see it. PHP 5.1.6-1 (cli) (built: Sep 1 2006 13:52:26) Copyright (c) 1997-2006 The PHP Group Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies Reproduce code: --------------- <? $descriptorSpec = array( 0 => array("pipe", "r"), // stdin is a pipe that the child process will read from 1 => array("pipe", "w"), // stdout is a pipe that the child process will write to 2 => array("pipe", "w") // stderr is a pipe that the child process will write to ); for ($i=0;$i<20;++$i) { $process = proc_open('/usr/bin/uptime', $descriptorSpec, $pipes); if (is_resource($process)) { fclose($pipes[0]); while(!feof($pipes[1])) $stdout .= fgets($pipes[1], 1024); fclose($pipes[1]); fclose($pipes[2]); } $returnValue = proc_close($process); unset($returnValue, $stdout, $stderr, $process, $pipes[0], $pipes[1], $pipes[2]); print $i . ' ==> ' . memory_get_usage() . "\r\n"; } ?> Expected result: ---------------- 0 ==> 41344 1 ==> 41408 2 ==> 41408 3 ==> 41408 4 ==> 41408 5 ==> 41408 6 ==> 41408 7 ==> 41408 8 ==> 41408 9 ==> 41408 10 ==> 41408 11 ==> 41408 12 ==> 41408 13 ==> 41408 14 ==> 41408 15 ==> 41408 16 ==> 41408 17 ==> 41408 18 ==> 41408 19 ==> 41408 (this is the actual result when replacing fgets with stream_get_line) Actual result: -------------- 0 ==> 41240 1 ==> 41368 2 ==> 41432 3 ==> 41496 4 ==> 41560 5 ==> 41624 6 ==> 41688 7 ==> 41752 8 ==> 41816 9 ==> 41880 10 ==> 41944 11 ==> 42008 12 ==> 42072 13 ==> 42136 14 ==> 42200 15 ==> 42264 16 ==> 42328 17 ==> 42392 18 ==> 42456 19 ==> 42520 -- Edit bug report at http://bugs.php.net/?id=38962&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=38962&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=38962&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=38962&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=38962&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=38962&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=38962&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=38962&r=needscript Try newer version: http://bugs.php.net/fix.php?id=38962&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=38962&r=support Expected behavior: http://bugs.php.net/fix.php?id=38962&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=38962&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=38962&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=38962&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=38962&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=38962&r=dst IIS Stability: http://bugs.php.net/fix.php?id=38962&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=38962&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=38962&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=38962&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=38962&r=mysqlcfg