ID: 50111 Updated by: j...@php.net -Summary: memory not properly freed when stream_context_create is used Reported By: datib...@php.net -Status: Open +Status: Wont fix Bug Type: Streams related Operating System: Linux PHP Version: 5.2.11 New Comment:
PHP 5.3 has better garbage collection, hence this works there and not in 5.2, wont fix for 5.2. Previous Comments: ------------------------------------------------------------------------ [2009-11-19 15:28:07] datib...@php.net My results for PHP 5.1.x were wrong, because I didn't compile them with --enable-memory-limit, so the ini_set() wasn't actually working for those; guess it was automatically added in 5.2.x even in the presence of --disable-all ... my bad =( After some more research on the PHP code itself, the problem seems to lie in the fact that the following two functions are called by stream_context_create(): zend_list_insert() - called by php_stream_context_alloc() zend_list_addref() - called by php_stream_context_to_zval() This results in a refcount of 2 for each context returned. This has changed in 5.3.x but not sure in how many places ;-) ------------------------------------------------------------------------ [2009-11-19 13:39:45] datib...@php.net I'm not trying to disable memory_limit. Setting it to "0" just happens to make the issue appear faster. Changing it to the below value of 1k yields the same results as mentioned earlier, tested on the same 5 php configurations: ini_set("memory_limit", "1000"); ------------------------------------------------------------------------ [2009-11-19 09:38:42] j...@php.net To disable memory_limit, you need to set it to -1, not 0. ------------------------------------------------------------------------ [2009-11-18 22:03:03] datib...@php.net <?php echo "This is PHP ", phpversion(),PHP_EOL; ini_set("memory_limit", "0"); for ($i=0;$i<2000;++$i) { $x = stream_context_create(array()); unset($x); } echo "Done", PHP_EOL; ?> ---------------- $ /usr/local/php-5.1.0/bin/php lala.php This is PHP 5.1.0 Done ---------------- $ /usr/local/php-5.1.1/bin/php lala.php This is PHP 5.1.1 Done ---------------- $ /usr/local/php-5.1.2/bin/php lala.php This is PHP 5.1.2 Done ---------------- $ /usr/local/php-5.2.9/bin/php lala.php This is PHP 5.2.9 Fatal error: Allowed memory size of 262144 bytes exhausted at /usr/local/src/php-5.2.9/Zend/zend_list.c:47 (tried to allocate 12 bytes) in /home/tjerk/lala.php on line 7 ---------------- $ /usr/local/php-5.2.11/bin/php lala.php This is PHP 5.2.11 Fatal error: Allowed memory size of 262144 bytes exhausted at /usr/local/src/php-5.2.11/main/streams/streams.c:1945 (tried to allocate 16 bytes) in /home/tjerk/lala.php on line 7 ---------------- $ /usr/local/php-5.3/bin/php lala.php This is PHP 5.3.0RC3-dev Done ------------------------------------------------------------------------ [2009-11-18 18:14:02] j...@php.net What code? There is no such script in this report that crashes. Not even when changed to loop thousands of times. Not with PHP_5_2 or PHP_5_3 or HEAD branches. So please, come up with a proper reproducing script. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/50111 -- Edit this bug report at http://bugs.php.net/?id=50111&edit=1