|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16148 fread function leaks memory when reading from socket
Submitted: 2002-03-18 12:33 UTC Modified: 2002-03-18 15:15 UTC
From: petri dot valisuo at lmf dot ericsson dot se Assigned:
Status: Closed Package: Sockets related
PHP Version: 4.1.2 OS: SunOS 5.8
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: petri dot valisuo at lmf dot ericsson dot se
New email:
PHP Version: OS:


 [2002-03-18 12:33 UTC] petri dot valisuo at lmf dot ericsson dot se
It seems that fread command leaks memory when data is 
read from a socket. It does not leak memory if it reads 
from open file descriptor. The speed of the process increse is as fast as the data flow, i.e. all bytes 
which are read leaks!

Here is a program that shows the problem. We have a file
server in the port 9229. When connection is opened there
and about 250 MB zip file is requested, the process dies
after it has received 8 MB of data. If the file is read
from an open file, the process size does not increse at
all, and it works perfectly.

header("Content-Type: application/octet-stream");	  
header("Content-Disposition: attachment;");
header("Content-Length: $len");

if(1) {
  $sock=fsockopen("localhost", 9229) or die ("Cannot open socket");
  fputs($sock, "GET\r\n");
else {
  $sock=fopen("", "r");

while(!feof($sock)) { 
  $recv_amount=(($len > $pkg_size) ? ($pkg_size): ($len));
  print fread($sock, $recv_amount);
  if($len<1) break;

Here is the configuration command of PHP 4.1.2 we are 
using, as reported by the phpinfo().

'./configure' '--with-apache=../apache_1.3.23' '--with-ldap=/data/usr/iPlanet/ldapcsdk414' '--prefix=/data' '--enable-memory-limit'


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-03-18 15:15 UTC]
This bug has been fixed in CVS.

PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Jul 01 11:05:45 2022 UTC