|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #10384 read() buffer memory not freed
Submitted: 2001-04-18 15:27 UTC Modified: 2001-05-17 10:38 UTC
From: rod at 23net dot net Assigned:
Status: Closed Package: Sockets related
PHP Version: 4.0.4pl1 OS: FreeBSD 4.2
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: rod at 23net dot net
New email:
PHP Version: OS:


 [2001-04-18 15:27 UTC] rod at 23net dot net
Using the  following code:

/* Allow the script to hang around waiting for connections. */
	set_time_limit (0);
#####	Connect to DB

#####	Open log file

$outMsgHeader="HTTP/1.1 200 OK\r\nDate: ";
$outMsgAfterDate=" GMT\r\nServer: PHP\r\nConnection: close\r\nTransfer-Encoding: chunked\r\nContent-Type: text/html\r\n\r\n";

if ($sock<0) 
	echo "socket() failed: reason: " . strerror ($sock) . "\n";

if (($ret = listen ($sock, 5)) < 0) 
	echo "listen() failed: reason: " . strerror ($ret) . "\n";


    if (($msgsock = accept_connect($sock)) < 0)
		echo "accept_connect() failed: reason: " . strerror ($msgsock) . "\n";
	if ($isPost===false) 
		if ($isGET===false) 
			write($msgsock,' HTTP/1.1 405\r\n',13);
			$endQS=strpos($buf,' ',$startQS);
			if (substr($buf,0,15)=="Content-length:") 
		} while ($buf != "\n");

		// through with headers, now get actual content
		// $buf now contains the query string
	$sendDate=gmdate('D, d M Y H:i:s');
    close ($msgsock);
} while (true);

(The function procMsg() is not relevent as for bug testing is set to return 'test')

Running this script causes memory to be consumed and not released with each connection.  I've narrowed the problem down to the read() function as I can affect the rate of memory consumption by modifying the length argument.  Evidently the buffer is not freed.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-05-03 13:33 UTC] rod at 23net dot net
Problem still exists in 4.0.5

The script originally uses ~2MB resident.  After connections are accepted it begins using memory in chunks specified in the read() function until it reaches ~6-6.5MB (varies with each run), at which time it continues to run without allocating more memory.
 [2001-05-17 10:38 UTC] rod at 23net dot net
This problem appears to be FreeBSD specific.  Still exists with FreeBSD 4.3 but is non-existent on Slackware.

Interesting side note:  I had modified the code below and introduced a bug which caused Slackware to send a 0 length message.  That is this line:


was changed to:


and should have been:


The variable $send was no longer defined resulting in the correct behavior under Slackware of sending no message, however under FreeBSD the full message was sent.

Since this appears to be a bug in the libraries under FreeBSD and NOT PHP related I'm closing the ticket.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Mon May 23 09:05:45 2022 UTC