cataphract Wed, 21 Dec 2011 15:44:58 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=321298
Log: - Fixed bug #60570 (http wrapper leaks context resource if request fails/is redirected). Bug: https://bugs.php.net/60570 (Verified) memory leak with create context Changed paths: U php/php-src/branches/PHP_5_3/ext/standard/http_fopen_wrapper.c A php/php-src/branches/PHP_5_3/ext/standard/tests/http/bug60570.phpt U php/php-src/branches/PHP_5_4/ext/standard/http_fopen_wrapper.c A php/php-src/branches/PHP_5_4/ext/standard/tests/http/bug60570.phpt U php/php-src/trunk/ext/standard/http_fopen_wrapper.c A php/php-src/trunk/ext/standard/tests/http/bug60570.phpt Modified: php/php-src/branches/PHP_5_3/ext/standard/http_fopen_wrapper.c =================================================================== --- php/php-src/branches/PHP_5_3/ext/standard/http_fopen_wrapper.c 2011-12-21 15:33:56 UTC (rev 321297) +++ php/php-src/branches/PHP_5_3/ext/standard/http_fopen_wrapper.c 2011-12-21 15:44:58 UTC (rev 321298) @@ -790,9 +790,6 @@ if (location[0] != '\0') php_stream_notify_info(context, PHP_STREAM_NOTIFY_REDIRECTED, location, 0); - if (context) { /* keep the context for the next try */ - zend_list_addref(context->rsrc_id); - } php_stream_close(stream); stream = NULL; Added: php/php-src/branches/PHP_5_3/ext/standard/tests/http/bug60570.phpt =================================================================== --- php/php-src/branches/PHP_5_3/ext/standard/tests/http/bug60570.phpt (rev 0) +++ php/php-src/branches/PHP_5_3/ext/standard/tests/http/bug60570.phpt 2011-12-21 15:44:58 UTC (rev 321298) @@ -0,0 +1,53 @@ +--TEST-- +Bug #60570 (Stream context leaks when http request fails) +--SKIPIF-- +<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?> +--INI-- +allow_url_fopen=1 +allow_url_include=1 +--FILE-- +<?php +require 'server.inc'; + +function do_test() { + + $responses = array( + "data://text/plain,HTTP/1.0 404 Not Found\r\n\r\n", + "data://text/plain,HTTP/1.0 404 Not Found\r\n\r\n", + "data://text/plain,HTTP/1.0 404 Not Found\r\n\r\n" + ); + + $pid = http_server("tcp://127.0.0.1:12342", $responses, $output); + + $a = $b = null; + + $i = 3; + while ($i--) { + $context = stream_context_create(array('http'=>array('timeout'=>1))); + file_get_contents('http://127.0.0.1:12342/', 0, $context); + unset($context); + + $b = $a; + $a = memory_get_usage(); + } + + http_server_kill($pid); + + echo "leak? penultimate iteration: $b, last one: $a\n"; + var_dump($a == $b); +} + +do_test(); + +--EXPECTF-- +Warning: file_get_contents(http://127.0.0.1:12342/): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found + in %s on line %d + +Warning: file_get_contents(http://127.0.0.1:12342/): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found + in %s on line %d + +Warning: file_get_contents(http://127.0.0.1:12342/): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found + in %s on line %d +leak? penultimate iteration: %d, last one: %d +bool(true) + Property changes on: php/php-src/branches/PHP_5_3/ext/standard/tests/http/bug60570.phpt ___________________________________________________________________ Added: svn:keywords + Id Rev Revision Added: svn:eol-style + native Modified: php/php-src/branches/PHP_5_4/ext/standard/http_fopen_wrapper.c =================================================================== --- php/php-src/branches/PHP_5_4/ext/standard/http_fopen_wrapper.c 2011-12-21 15:33:56 UTC (rev 321297) +++ php/php-src/branches/PHP_5_4/ext/standard/http_fopen_wrapper.c 2011-12-21 15:44:58 UTC (rev 321298) @@ -787,9 +787,6 @@ if (location[0] != '\0') php_stream_notify_info(context, PHP_STREAM_NOTIFY_REDIRECTED, location, 0); - if (context) { /* keep the context for the next try */ - zend_list_addref(context->rsrc_id); - } php_stream_close(stream); stream = NULL; Added: php/php-src/branches/PHP_5_4/ext/standard/tests/http/bug60570.phpt =================================================================== --- php/php-src/branches/PHP_5_4/ext/standard/tests/http/bug60570.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/ext/standard/tests/http/bug60570.phpt 2011-12-21 15:44:58 UTC (rev 321298) @@ -0,0 +1,53 @@ +--TEST-- +Bug #60570 (Stream context leaks when http request fails) +--SKIPIF-- +<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?> +--INI-- +allow_url_fopen=1 +allow_url_include=1 +--FILE-- +<?php +require 'server.inc'; + +function do_test() { + + $responses = array( + "data://text/plain,HTTP/1.0 404 Not Found\r\n\r\n", + "data://text/plain,HTTP/1.0 404 Not Found\r\n\r\n", + "data://text/plain,HTTP/1.0 404 Not Found\r\n\r\n" + ); + + $pid = http_server("tcp://127.0.0.1:12342", $responses, $output); + + $a = $b = null; + + $i = 3; + while ($i--) { + $context = stream_context_create(array('http'=>array('timeout'=>1))); + file_get_contents('http://127.0.0.1:12342/', 0, $context); + unset($context); + + $b = $a; + $a = memory_get_usage(); + } + + http_server_kill($pid); + + echo "leak? penultimate iteration: $b, last one: $a\n"; + var_dump($a == $b); +} + +do_test(); + +--EXPECTF-- +Warning: file_get_contents(http://127.0.0.1:12342/): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found + in %s on line %d + +Warning: file_get_contents(http://127.0.0.1:12342/): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found + in %s on line %d + +Warning: file_get_contents(http://127.0.0.1:12342/): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found + in %s on line %d +leak? penultimate iteration: %d, last one: %d +bool(true) + Property changes on: php/php-src/branches/PHP_5_4/ext/standard/tests/http/bug60570.phpt ___________________________________________________________________ Added: svn:keywords + Id Rev Revision Added: svn:eol-style + native Modified: php/php-src/trunk/ext/standard/http_fopen_wrapper.c =================================================================== --- php/php-src/trunk/ext/standard/http_fopen_wrapper.c 2011-12-21 15:33:56 UTC (rev 321297) +++ php/php-src/trunk/ext/standard/http_fopen_wrapper.c 2011-12-21 15:44:58 UTC (rev 321298) @@ -787,9 +787,6 @@ if (location[0] != '\0') php_stream_notify_info(context, PHP_STREAM_NOTIFY_REDIRECTED, location, 0); - if (context) { /* keep the context for the next try */ - zend_list_addref(context->rsrc_id); - } php_stream_close(stream); stream = NULL; Added: php/php-src/trunk/ext/standard/tests/http/bug60570.phpt =================================================================== --- php/php-src/trunk/ext/standard/tests/http/bug60570.phpt (rev 0) +++ php/php-src/trunk/ext/standard/tests/http/bug60570.phpt 2011-12-21 15:44:58 UTC (rev 321298) @@ -0,0 +1,53 @@ +--TEST-- +Bug #60570 (Stream context leaks when http request fails) +--SKIPIF-- +<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?> +--INI-- +allow_url_fopen=1 +allow_url_include=1 +--FILE-- +<?php +require 'server.inc'; + +function do_test() { + + $responses = array( + "data://text/plain,HTTP/1.0 404 Not Found\r\n\r\n", + "data://text/plain,HTTP/1.0 404 Not Found\r\n\r\n", + "data://text/plain,HTTP/1.0 404 Not Found\r\n\r\n" + ); + + $pid = http_server("tcp://127.0.0.1:12342", $responses, $output); + + $a = $b = null; + + $i = 3; + while ($i--) { + $context = stream_context_create(array('http'=>array('timeout'=>1))); + file_get_contents('http://127.0.0.1:12342/', 0, $context); + unset($context); + + $b = $a; + $a = memory_get_usage(); + } + + http_server_kill($pid); + + echo "leak? penultimate iteration: $b, last one: $a\n"; + var_dump($a == $b); +} + +do_test(); + +--EXPECTF-- +Warning: file_get_contents(http://127.0.0.1:12342/): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found + in %s on line %d + +Warning: file_get_contents(http://127.0.0.1:12342/): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found + in %s on line %d + +Warning: file_get_contents(http://127.0.0.1:12342/): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found + in %s on line %d +leak? penultimate iteration: %d, last one: %d +bool(true) + Property changes on: php/php-src/trunk/ext/standard/tests/http/bug60570.phpt ___________________________________________________________________ Added: svn:keywords + Id Rev Revision Added: svn:eol-style + native
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php