php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29511 popen memory leak
Submitted: 2004-08-03 22:01 UTC Modified: 2004-08-17 17:58 UTC
From: mario at mariomedina dot net Assigned:
Status: Not a bug Package: Reproducible crash
PHP Version: 5.0.0 OS: Linux
Private report: No CVE-ID: None
 [2004-08-03 22:01 UTC] mario at mariomedina dot net
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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-08-17 17:58 UTC] tony2001@php.net
Can't find any leaks/bugs there. It's quite expected that memory consumption at the end of the script will be greater than at the beginning. 
All this memory is being freed at the end of the request, so there is no leaks at all. 
Btw, PHP reports memleaks (if you turned on appropriate option in php.ini), so you'll see them when they really happen.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 20 20:00:03 2025 UTC