php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61371 stream_context_create() causes memory leaks on use streams_socket_create
Submitted: 2012-03-13 10:29 UTC Modified: 2012-03-17 19:37 UTC
From: raiderz at gmail dot com Assigned: cataphract (profile)
Status: Closed Package: Streams related
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: raiderz at gmail dot com
New email:
PHP Version: OS:

 

 [2012-03-13 10:29 UTC] raiderz at gmail dot com
Description:
------------
stream_context_create() causes memory leaks on use width stream_socket_client
Version PHP 5.3.6

Test script:
---------------
for($test=1;$test<=5;$test++) {
	echo 'memory: '.round(memory_get_usage()/1024, 0)."kb\n";
	for($i=0;$i<=100;$i++) {
		$context = stream_context_create(array());
		$stream = stream_socket_client('udp://0.0.0.0:80', $errno, $errstr, 10, STREAM_CLIENT_CONNECT, $context);
		fclose($stream);
		unset($context);
		unset($stream);
	}
}

Expected result:
----------------
memory: 615kb
memory: 674kb
memory: 732kb
memory: 790kb
memory: 847kb



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-03-13 14:32 UTC] cataphract@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2012-03-13 14:32 UTC] cataphract@php.net
-Status: Open +Status: Feedback
 [2012-03-13 15:34 UTC] raiderz at gmail dot com
-Status: Feedback +Status: Open
 [2012-03-13 15:34 UTC] raiderz at gmail dot com
I update to 5.3.11-dev from snaps, bug already have in this version.

New result:
memory: 317kb
memory: 338kb
memory: 359kb
memory: 380kb
memory: 400kb
 [2012-03-14 08:28 UTC] cataphract@php.net
This was fixed in trunk in r323478. If you unset also $errno and $errstr you have constant memory. PHP 5.4 still has the resource leak fixed in that revision because the fix has not been merged yet.

PHP 5.3 seems to (also?) have a different and more serious leak.

trunk:
memory: 223kb
memory: 223kb
memory: 223kb
memory: 223kb
memory: 223kb

5.4:
memory: 223kb
memory: 290kb
memory: 356kb
memory: 424kb
memory: 489kb

5.3:
memory: 629kb
memory: 711kb
memory: 792kb
memory: 875kb
memory: 955kb

I'll investigate later the problem in 5.3.
 [2012-03-14 08:28 UTC] cataphract@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: cataphract
 [2012-03-17 19:37 UTC] cataphract@php.net
Automatic comment from SVN on behalf of cataphract
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=324324
Log: - Fixed bug #61371 (resource leak). This bug had two parts, a long standing leak
  already fixed in trunk/5.3 and now merged onto 5.4 and a leak introduced in
  fixing bug #61115. This better fix for #61115 fixes the leak (the inhibition
  for deleting the context was too broad) and so prevents segfaults in new
  circumstances (where the inhibition was not broad enough).
 [2012-03-17 19:37 UTC] cataphract@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2012-03-17 19:37 UTC] cataphract@php.net
-Status: Verified +Status: Closed
 [2012-04-18 09:45 UTC] laruence@php.net
Automatic comment on behalf of cataphract
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e132db7a57a6afc53cceec15f19541ec29d8233a
Log: - Fixed bug #61371 (resource leak). This bug had two parts, a long standing leak   already fixed in trunk/5.3 and now merged onto 5.4 and a leak introduced in   fixing bug #61115. This better fix for #61115 fixes the leak (the inhibition   for deleting the context was too broad) and so prevents segfaults in new   circumstances (where the inhibition was not broad enough).
 [2012-04-26 11:32 UTC] ab@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=4e9db5ba9fd0dcaa5f86dc644dfa8a7897ae8dd7
Log: Fix bug #61800 ext\standard\tests\streams\bug61371.phpt fails
 [2012-07-24 23:36 UTC] rasmus@php.net
Automatic comment on behalf of cataphract
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e132db7a57a6afc53cceec15f19541ec29d8233a
Log: - Fixed bug #61371 (resource leak). This bug had two parts, a long standing leak   already fixed in trunk/5.3 and now merged onto 5.4 and a leak introduced in   fixing bug #61115. This better fix for #61115 fixes the leak (the inhibition   for deleting the context was too broad) and so prevents segfaults in new   circumstances (where the inhibition was not broad enough).
 [2013-11-17 09:33 UTC] laruence@php.net
Automatic comment on behalf of cataphract
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e132db7a57a6afc53cceec15f19541ec29d8233a
Log: - Fixed bug #61371 (resource leak). This bug had two parts, a long standing leak   already fixed in trunk/5.3 and now merged onto 5.4 and a leak introduced in   fixing bug #61115. This better fix for #61115 fixes the leak (the inhibition   for deleting the context was too broad) and so prevents segfaults in new   circumstances (where the inhibition was not broad enough).
 [2014-10-07 23:26 UTC] stas@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=4e9db5ba9fd0dcaa5f86dc644dfa8a7897ae8dd7
Log: Fix bug #61800 ext\standard\tests\streams\bug61371.phpt fails
 [2014-10-07 23:37 UTC] stas@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=4e9db5ba9fd0dcaa5f86dc644dfa8a7897ae8dd7
Log: Fix bug #61800 ext\standard\tests\streams\bug61371.phpt fails
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC