Better fix for #51605

This commit is contained in:
Andrey Hristov 2010-05-13 11:05:09 +00:00
parent fdfdb1480e
commit 6cefa510d6
4 changed files with 20 additions and 7 deletions

View File

@ -222,10 +222,11 @@ static void mysqli_link_free_storage(void *object TSRMLS_DC)
if (my_res && my_res->ptr) {
MY_MYSQL *mysql = (MY_MYSQL *)my_res->ptr;
if (mysql->mysql) {
php_mysqli_close(mysql, MYSQLI_CLOSE_EXPLICIT TSRMLS_CC);
php_mysqli_close(mysql, MYSQLI_CLOSE_EXPLICIT, my_res->status TSRMLS_CC);
}
php_clear_mysql(mysql);
efree(mysql);
my_res->status = MYSQLI_STATUS_UNKNOWN;
}
mysqli_objects_free_storage(object TSRMLS_CC);
}

View File

@ -551,8 +551,12 @@ PHP_FUNCTION(mysqli_character_set_name)
/* {{{ php_mysqli_close */
void php_mysqli_close(MY_MYSQL * mysql, int close_type TSRMLS_DC)
void php_mysqli_close(MY_MYSQL * mysql, int close_type, int resource_status TSRMLS_DC)
{
if (resource_status > MYSQLI_STATUS_INITIALIZED) {
MyG(num_links)--;
}
if (!mysql->persistent) {
mysqli_close(mysql->mysql, close_type);
} else {
@ -569,7 +573,6 @@ void php_mysqli_close(MY_MYSQL * mysql, int close_type TSRMLS_DC)
mysql->persistent = FALSE;
}
mysql->mysql = NULL;
MyG(num_links)--;
php_clear_mysql(mysql);
}
@ -589,7 +592,8 @@ PHP_FUNCTION(mysqli_close)
MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_INITIALIZED);
php_mysqli_close(mysql, MYSQLI_CLOSE_EXPLICIT TSRMLS_CC);
php_mysqli_close(mysql, MYSQLI_CLOSE_EXPLICIT, ((MYSQLI_RESOURCE *)((mysqli_object *)zend_object_store_get_object(mysql_link TSRMLS_CC))->ptr)->status TSRMLS_CC);
((MYSQLI_RESOURCE *)((mysqli_object *)zend_object_store_get_object(mysql_link TSRMLS_CC))->ptr)->status = MYSQLI_STATUS_UNKNOWN;
MYSQLI_CLEAR_RESOURCE(&mysql_link);
efree(mysql);

View File

@ -124,7 +124,7 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
}
if (mysql->mysql && mysqli_resource && mysqli_resource->status > MYSQLI_STATUS_INITIALIZED) {
/* already connected, we should close the connection */
php_mysqli_close(mysql, MYSQLI_CLOSE_IMPLICIT TSRMLS_CC);
php_mysqli_close(mysql, MYSQLI_CLOSE_IMPLICIT, mysqli_resource->status TSRMLS_CC);
}
if (!socket_len || !socket) {
@ -199,11 +199,11 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
}
}
}
if (MyG(max_links) != -1 && MyG(num_links) >= MyG(max_links)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Too many open links (%ld)", MyG(num_links));
goto err;
}
if (persistent && MyG(max_persistent) != -1 &&
(MyG(num_active_persistent) + MyG(num_inactive_persistent))>= MyG(max_persistent))
{

View File

@ -1,5 +1,5 @@
--TEST--
Bug #51647 (Certificate file without private key (pk in another file) doesn't work)
Bug #51605 Mysqli - zombie links
--SKIPIF--
<?php
require_once('skipif.inc');
@ -28,9 +28,17 @@ mysqli.reconnect = Off
mysqli_close($link);
echo "closed twice\n";
$link = mysqli_init();
if (!my_mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket)) {
printf("[003] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
}
mysqli_close($link);
echo "closed for third time\n";
print "done!";
?>
--EXPECTF--
closed once
closed twice
closed for third time
done!