andrey                                   Thu, 30 Sep 2010 18:10:03 +0000

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

Log:
Plug a leak in mysqli when in the same script
a pconn is reused.
Call end_psession earlier - so will mysqlnd and
the plugins free data earlier.

Changed paths:
    U   php/php-src/branches/PHP_5_3/ext/mysql/php_mysql.c
    U   php/php-src/branches/PHP_5_3/ext/mysqli/mysqli.c
    U   php/php-src/branches/PHP_5_3/ext/mysqli/mysqli_api.c
    U   php/php-src/branches/PHP_5_3/ext/mysqli/mysqli_nonapi.c
    U   php/php-src/trunk/ext/mysql/php_mysql.c
    U   php/php-src/trunk/ext/mysqli/mysqli.c
    U   php/php-src/trunk/ext/mysqli/mysqli_api.c
    U   php/php-src/trunk/ext/mysqli/mysqli_nonapi.c

Modified: php/php-src/branches/PHP_5_3/ext/mysql/php_mysql.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysql/php_mysql.c  2010-09-30 15:26:56 UTC 
(rev 303896)
+++ php/php-src/branches/PHP_5_3/ext/mysql/php_mysql.c  2010-09-30 18:10:03 UTC 
(rev 303897)
@@ -637,7 +637,7 @@
                efree(MySG(connect_error));
        }

-#ifdef MYSQL_USE_MYSQLND
+#ifdef A0 && MYSQL_USE_MYSQLND
        zend_hash_apply(&EG(persistent_list), (apply_func_t) 
php_mysql_persistent_helper TSRMLS_CC);
 #endif

@@ -888,7 +888,7 @@
                        mysql->multi_query = 0;
 #endif
                        /* ensure that the link did not die */
-#if defined(MYSQL_USE_MYSQLND)
+#if A0 && defined(MYSQL_USE_MYSQLND)
                        mysqlnd_end_psession(mysql->conn);
 #endif
                        if (mysql_ping(mysql->conn)) {

Modified: php/php-src/branches/PHP_5_3/ext/mysqli/mysqli.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqli/mysqli.c    2010-09-30 15:26:56 UTC 
(rev 303896)
+++ php/php-src/branches/PHP_5_3/ext/mysqli/mysqli.c    2010-09-30 18:10:03 UTC 
(rev 303897)
@@ -893,7 +893,8 @@
        if (MyG(error_msg)) {
                efree(MyG(error_msg));
        }
-#ifdef MYSQLI_USE_MYSQLND
+#ifdef A0 && MYSQLI_USE_MYSQLND
+       /* psession is being called when the connection is freed - explicitly 
or implicitly */
        zend_hash_apply(&EG(persistent_list), (apply_func_t) 
php_mysqli_persistent_helper_once TSRMLS_CC);
 #endif
        return SUCCESS;

Modified: php/php-src/branches/PHP_5_3/ext/mysqli/mysqli_api.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqli/mysqli_api.c        2010-09-30 
15:26:56 UTC (rev 303896)
+++ php/php-src/branches/PHP_5_3/ext/mysqli/mysqli_api.c        2010-09-30 
18:10:03 UTC (rev 303897)
@@ -588,6 +588,9 @@
                if (zend_hash_find(&EG(persistent_list), mysql->hash_key, 
strlen(mysql->hash_key) + 1, (void **)&le) == SUCCESS) {
                        if (Z_TYPE_P(le) == php_le_pmysqli()) {
                                mysqli_plist_entry *plist = (mysqli_plist_entry 
*) le->ptr;
+#if defined(MYSQLI_USE_MYSQLND)
+                               mysqlnd_end_psession(mysql->mysql);
+#endif
                                zend_ptr_stack_push(&plist->free_links, 
mysql->mysql);

                                MyG(num_active_persistent)--;

Modified: php/php-src/branches/PHP_5_3/ext/mysqli/mysqli_nonapi.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqli/mysqli_nonapi.c     2010-09-30 
15:26:56 UTC (rev 303896)
+++ php/php-src/branches/PHP_5_3/ext/mysqli/mysqli_nonapi.c     2010-09-30 
18:10:03 UTC (rev 303897)
@@ -123,7 +123,7 @@
                        flags &= ~CLIENT_LOCAL_FILES;
                }
        }
-       if (mysql->mysql && mysqli_resource && mysqli_resource->status > 
MYSQLI_STATUS_INITIALIZED) {
+       if (mysql->mysql && mysqli_resource && (mysqli_resource->status > 
MYSQLI_STATUS_INITIALIZED || (strlen(SAFE_STR(hostname)) > 2 && 
!strncasecmp(hostname, "p:", 2)))) {
                /* already connected, we should close the connection */
                php_mysqli_close(mysql, MYSQLI_CLOSE_IMPLICIT, 
mysqli_resource->status TSRMLS_CC);
        }
@@ -168,9 +168,6 @@
                                                        mysql->mysql = 
zend_ptr_stack_pop(&plist->free_links);

                                                        
MyG(num_inactive_persistent)--;
-#if defined(MYSQLI_USE_MYSQLND)
-                                                       
mysqlnd_end_psession(mysql->mysql);
-#endif
                                                        /* reset variables */

 #ifndef MYSQLI_NO_CHANGE_USER_ON_PCONNECT

Modified: php/php-src/trunk/ext/mysql/php_mysql.c
===================================================================
--- php/php-src/trunk/ext/mysql/php_mysql.c     2010-09-30 15:26:56 UTC (rev 
303896)
+++ php/php-src/trunk/ext/mysql/php_mysql.c     2010-09-30 18:10:03 UTC (rev 
303897)
@@ -637,7 +637,7 @@
                efree(MySG(connect_error));
        }

-#ifdef MYSQL_USE_MYSQLND
+#ifdef A0 && MYSQL_USE_MYSQLND
        zend_hash_apply(&EG(persistent_list), (apply_func_t) 
php_mysql_persistent_helper TSRMLS_CC);
 #endif

@@ -888,7 +888,7 @@
                        mysql->multi_query = 0;
 #endif
                        /* ensure that the link did not die */
-#if defined(MYSQL_USE_MYSQLND)
+#if A0 && defined(MYSQL_USE_MYSQLND)
                        mysqlnd_end_psession(mysql->conn);
 #endif
                        if (mysql_ping(mysql->conn)) {

Modified: php/php-src/trunk/ext/mysqli/mysqli.c
===================================================================
--- php/php-src/trunk/ext/mysqli/mysqli.c       2010-09-30 15:26:56 UTC (rev 
303896)
+++ php/php-src/trunk/ext/mysqli/mysqli.c       2010-09-30 18:10:03 UTC (rev 
303897)
@@ -895,7 +895,8 @@
        if (MyG(error_msg)) {
                efree(MyG(error_msg));
        }
-#ifdef MYSQLI_USE_MYSQLND
+#ifdef A0 && MYSQLI_USE_MYSQLND
+       /* psession is being called when the connection is freed - explicitly 
or implicitly */
        zend_hash_apply(&EG(persistent_list), (apply_func_t) 
php_mysqli_persistent_helper_once TSRMLS_CC);
 #endif
        return SUCCESS;

Modified: php/php-src/trunk/ext/mysqli/mysqli_api.c
===================================================================
--- php/php-src/trunk/ext/mysqli/mysqli_api.c   2010-09-30 15:26:56 UTC (rev 
303896)
+++ php/php-src/trunk/ext/mysqli/mysqli_api.c   2010-09-30 18:10:03 UTC (rev 
303897)
@@ -588,6 +588,9 @@
                if (zend_hash_find(&EG(persistent_list), mysql->hash_key, 
strlen(mysql->hash_key) + 1, (void **)&le) == SUCCESS) {
                        if (Z_TYPE_P(le) == php_le_pmysqli()) {
                                mysqli_plist_entry *plist = (mysqli_plist_entry 
*) le->ptr;
+#if defined(MYSQLI_USE_MYSQLND)
+                               mysqlnd_end_psession(mysql->mysql);
+#endif
                                zend_ptr_stack_push(&plist->free_links, 
mysql->mysql);

                                MyG(num_active_persistent)--;

Modified: php/php-src/trunk/ext/mysqli/mysqli_nonapi.c
===================================================================
--- php/php-src/trunk/ext/mysqli/mysqli_nonapi.c        2010-09-30 15:26:56 UTC 
(rev 303896)
+++ php/php-src/trunk/ext/mysqli/mysqli_nonapi.c        2010-09-30 18:10:03 UTC 
(rev 303897)
@@ -123,7 +123,7 @@
                        flags &= ~CLIENT_LOCAL_FILES;
                }
        }
-       if (mysql->mysql && mysqli_resource && mysqli_resource->status > 
MYSQLI_STATUS_INITIALIZED) {
+       if (mysql->mysql && mysqli_resource && (mysqli_resource->status > 
MYSQLI_STATUS_INITIALIZED || (strlen(SAFE_STR(hostname)) > 2 && 
!strncasecmp(hostname, "p:", 2)))) {
                /* already connected, we should close the connection */
                php_mysqli_close(mysql, MYSQLI_CLOSE_IMPLICIT, 
mysqli_resource->status TSRMLS_CC);
        }
@@ -168,9 +168,6 @@
                                                        mysql->mysql = 
zend_ptr_stack_pop(&plist->free_links);

                                                        
MyG(num_inactive_persistent)--;
-#if defined(MYSQLI_USE_MYSQLND)
-                                                       
mysqlnd_end_psession(mysql->mysql);
-#endif
                                                        /* reset variables */

 #ifndef MYSQLI_NO_CHANGE_USER_ON_PCONNECT

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

Reply via email to