mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
A fix and test case for Bug#5315 "mysql_change_user() doesn't free
prepared statements." include/hash.h: New declaration for hash_reset() function. The old version was not used. libmysql/client_settings.h: Declaration for mysql_detach_stmt_list(). libmysql/libmysql.c: Fix for bug#5315 "mysql_change_user() doesn't free prepared statements": add call to mysql_detach_stmt_list(prepared statements) to mysql_change_user(): all statements are freed by server, so client counterparts need to be marked as not usable. mysys/hash.c: Fix for bug#5315 "mysql_change_user() doesn't free prepared statements": implementation of hash_reset(), which frees all hash elements and prepares the hash for reuse. sql-common/client.c: Fix for bug#5315 "mysql_change_user() doesn't free prepared statements": implementation of mysql_detach_stmt_list(): zero connection pointer in given statement list, thus marking given statements as not usable. sql/sql_class.cc: Fix for bug#5315 "mysql_change_user() doesn't free prepared statements": reset prepared statements map in THD::change_user(). sql/sql_class.h: Fix for bug#5315 "mysql_change_user() doesn't free prepared statements": implementation of Statement_map::reset(). A little cleanup of ~Statement_map(): first empty names_hash, as st_hash has a free function, which will delete statements. tests/client_test.c: A test case for bug #5315 "mysql_change_user() doesn't free prepared statements".
This commit is contained in:
@@ -2239,6 +2239,32 @@ static void mysql_close_free(MYSQL *mysql)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Clear connection pointer of every statement: this is necessary
|
||||
to give error on attempt to use a prepared statement of closed
|
||||
connection.
|
||||
|
||||
SYNOPSYS
|
||||
mysql_detach_stmt_list()
|
||||
stmt_list pointer to mysql->stmts
|
||||
*/
|
||||
|
||||
void mysql_detach_stmt_list(LIST **stmt_list)
|
||||
{
|
||||
#ifdef MYSQL_CLIENT
|
||||
/* Reset connection handle in all prepared statements. */
|
||||
LIST *element= *stmt_list;
|
||||
for (; element; element= element->next)
|
||||
{
|
||||
MYSQL_STMT *stmt= (MYSQL_STMT *) element->data;
|
||||
stmt->mysql= 0;
|
||||
/* No need to call list_delete for statement here */
|
||||
}
|
||||
*stmt_list= 0;
|
||||
#endif /* MYSQL_CLIENT */
|
||||
}
|
||||
|
||||
|
||||
void STDCALL mysql_close(MYSQL *mysql)
|
||||
{
|
||||
DBUG_ENTER("mysql_close");
|
||||
@@ -2255,20 +2281,7 @@ void STDCALL mysql_close(MYSQL *mysql)
|
||||
}
|
||||
mysql_close_free_options(mysql);
|
||||
mysql_close_free(mysql);
|
||||
#ifdef MYSQL_CLIENT
|
||||
if (mysql->stmts)
|
||||
{
|
||||
/* Reset connection handle in all prepared statements. */
|
||||
LIST *element;
|
||||
for (element= mysql->stmts; element; element= element->next)
|
||||
{
|
||||
MYSQL_STMT *stmt= (MYSQL_STMT *) element->data;
|
||||
stmt->mysql= 0;
|
||||
/* No need to call list_delete for statement here */
|
||||
}
|
||||
mysql->stmts= 0;
|
||||
}
|
||||
#endif /*MYSQL_CLIENT*/
|
||||
mysql_detach_stmt_list(&mysql->stmts);
|
||||
#ifndef TO_BE_DELETED
|
||||
/* free/close slave list */
|
||||
if (mysql->rpl_pivot)
|
||||
|
Reference in New Issue
Block a user