mirror of
https://github.com/php/php-src.git
synced 2026-04-05 07:02:33 +02:00
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.
This commit is contained in:
@@ -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)) {
|
||||
|
||||
@@ -895,7 +895,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;
|
||||
|
||||
@@ -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)--;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user