summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Hristov <andrey@php.net>2010-09-30 18:10:03 +0000
committerAndrey Hristov <andrey@php.net>2010-09-30 18:10:03 +0000
commit60327d87a7599ce5288a9fb7675f20f3ec29c7ff (patch)
tree645dd352c9ac5c2f6dce41feac3b7c11182c839e
parent5c6f0ebeabd5ee4d8bd79f158fd7ee968ac28c0d (diff)
downloadphp-git-60327d87a7599ce5288a9fb7675f20f3ec29c7ff.tar.gz
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.
-rw-r--r--ext/mysql/php_mysql.c4
-rw-r--r--ext/mysqli/mysqli.c3
-rw-r--r--ext/mysqli/mysqli_api.c3
-rw-r--r--ext/mysqli/mysqli_nonapi.c5
4 files changed, 8 insertions, 7 deletions
diff --git a/ext/mysql/php_mysql.c b/ext/mysql/php_mysql.c
index ab1d2a001e..2ef9aa950d 100644
--- a/ext/mysql/php_mysql.c
+++ b/ext/mysql/php_mysql.c
@@ -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)) {
diff --git a/ext/mysqli/mysqli.c b/ext/mysqli/mysqli.c
index 0325e89ce5..b45622920d 100644
--- a/ext/mysqli/mysqli.c
+++ b/ext/mysqli/mysqli.c
@@ -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;
diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c
index 644598225f..6b8891dd8b 100644
--- a/ext/mysqli/mysqli_api.c
+++ b/ext/mysqli/mysqli_api.c
@@ -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)--;
diff --git a/ext/mysqli/mysqli_nonapi.c b/ext/mysqli/mysqli_nonapi.c
index 3c075970bb..4334fc53c9 100644
--- a/ext/mysqli/mysqli_nonapi.c
+++ b/ext/mysqli/mysqli_nonapi.c
@@ -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