andrey                                   Thu, 01 Apr 2010 11:50:24 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=297271

Log:
Fixed bug #51347 mysqli_close / connection memory leak
Streams API registers every stream as resource, which lands then
in EG(regular_list), however doesn't clean that when the stream is
closed. At the end this is a para-leak. At the end of the script
all memory is cleaned, however this is a problem for long runnig
scripts that open connections. For every opened and closed connection
about 150 Bytes on 32bit and 250 Bytes on 64bit will be "lost",
according to memory_get_usage().

Bug: http://bugs.php.net/51347 (Open) mysqli_close / connection memory leak
      
Changed paths:
    U   php/php-src/branches/PHP_5_3/NEWS
    U   php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_net.c
    U   php/php-src/trunk/ext/mysqlnd/mysqlnd_net.c

Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS   2010-04-01 11:32:44 UTC (rev 297270)
+++ php/php-src/branches/PHP_5_3/NEWS   2010-04-01 11:50:24 UTC (rev 297271)
@@ -13,6 +13,7 @@

 - Fixed bug #51393 (DateTime::createFromFormat() fails if format string 
contains
   timezone). (Adam)
+- Fixed bug #51347 (mysqli_close / connection memory leak). (Andrey, Johannes)
 - Fixed bug #51338 (URL-Rewriter is still enabled if use_only_cookies is
   on). (Ilia, j dot jeising at gmail dot com)
 - Fixed bug #51269 (zlib.output_compression Overwrites Vary Header). (Adam)

Modified: php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_net.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_net.c      2010-04-01 
11:32:44 UTC (rev 297270)
+++ php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_net.c      2010-04-01 
11:50:24 UTC (rev 297271)
@@ -703,6 +703,14 @@
                        mnd_pefree(net->cmd_buffer.buffer, pers);
                        net->cmd_buffer.buffer = NULL;
                }
+               /*
+                 Streams are not meant for C extensions! Thus we need a hack. 
Every connected stream will
+                 be registered as resource (in EG(regular_list). So far, so 
good. However, it won't be
+                 unregistered till the script ends. So, we need to take care 
of that.
+                 */
+               net->stream->in_free = 1;
+               zend_hash_index_del(&EG(regular_list), net->stream->rsrc_id);
+               net->stream->in_free = 0;

                if (net->stream) {
                        DBG_INF_FMT("Freeing stream. abstract=%p", 
net->stream->abstract);

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd_net.c
===================================================================
--- php/php-src/trunk/ext/mysqlnd/mysqlnd_net.c 2010-04-01 11:32:44 UTC (rev 
297270)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd_net.c 2010-04-01 11:50:24 UTC (rev 
297271)
@@ -703,6 +703,14 @@
                        mnd_pefree(net->cmd_buffer.buffer, pers);
                        net->cmd_buffer.buffer = NULL;
                }
+               /*
+                 Streams are not meant for C extensions! Thus we need a hack. 
Every connected stream will
+                 be registered as resource (in EG(regular_list). So far, so 
good. However, it won't be
+                 unregistered till the script ends. So, we need to take care 
of that.
+                 */
+               net->stream->in_free = 1;
+               zend_hash_index_del(&EG(regular_list), net->stream->rsrc_id);
+               net->stream->in_free = 0;

                if (net->stream) {
                        DBG_INF_FMT("Freeing stream. abstract=%p", 
net->stream->abstract);

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to