]> granicus.if.org Git - php/commitdiff
Plug a leak in mysqli when in the same script
authorAndrey Hristov <andrey@php.net>
Thu, 30 Sep 2010 18:10:03 +0000 (18:10 +0000)
committerAndrey Hristov <andrey@php.net>
Thu, 30 Sep 2010 18:10:03 +0000 (18:10 +0000)
a pconn is reused.
Call end_psession earlier - so will mysqlnd and
the plugins free data earlier.

ext/mysql/php_mysql.c
ext/mysqli/mysqli.c
ext/mysqli/mysqli_api.c
ext/mysqli/mysqli_nonapi.c

index ab1d2a001edb4f7b012d73703f0b78cac91cff57..2ef9aa950d3d086d047c189cdc3a219ccc271b5a 100644 (file)
@@ -637,7 +637,7 @@ PHP_RSHUTDOWN_FUNCTION(mysql)
                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 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
                        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)) {
index 0325e89ce52b39beefdf7d4cef9b15104b597a01..b45622920de7ec51097873dbb6ea0a7898fd9425 100644 (file)
@@ -893,7 +893,8 @@ PHP_RSHUTDOWN_FUNCTION(mysqli)
        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;
index 644598225fe28a572dfff044c0a7ef958f922be3..6b8891dd8b1886606a67c40a1409c1f2bf22879a 100644 (file)
@@ -588,6 +588,9 @@ void php_mysqli_close(MY_MYSQL * mysql, int close_type, int resource_status TSRM
                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)--;
index 3c075970bbf8b700f0ed0ee6027cb2f42a8f3966..4334fc53c9abcbf297f24b779b0b6e21c31944a2 100644 (file)
@@ -123,7 +123,7 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
                        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 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
                                                        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