diff options
author | unknown <konstantin@mysql.com> | 2004-09-22 15:50:07 +0400 |
---|---|---|
committer | unknown <konstantin@mysql.com> | 2004-09-22 15:50:07 +0400 |
commit | ccf52b4fd5bd7ae0a418d22f2758cef345b6afa6 (patch) | |
tree | e9e451c78db8c48bfcfbf6943d785f85d1b8a6f8 /libmysql | |
parent | d594d40d119fd536657be3b1523bd5b48f15fa1e (diff) | |
download | mariadb-git-ccf52b4fd5bd7ae0a418d22f2758cef345b6afa6.tar.gz |
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".
Diffstat (limited to 'libmysql')
-rw-r--r-- | libmysql/client_settings.h | 1 | ||||
-rw-r--r-- | libmysql/libmysql.c | 33 |
2 files changed, 22 insertions, 12 deletions
diff --git a/libmysql/client_settings.h b/libmysql/client_settings.h index 5857c0c84d6..552307733ea 100644 --- a/libmysql/client_settings.h +++ b/libmysql/client_settings.h @@ -42,6 +42,7 @@ my_bool handle_local_infile(MYSQL *mysql, const char *net_filename); void mysql_read_default_options(struct st_mysql_options *options, const char *filename,const char *group); +void mysql_detach_stmt_list(LIST **stmt_list); MYSQL * STDCALL cli_mysql_real_connect(MYSQL *mysql,const char *host, const char *user, const char *passwd, const char *db, diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 6601d3e4ad7..2ad6771cc69 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -662,6 +662,7 @@ my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, const char *passwd, const char *db) { char buff[512],*end=buff; + int rc; DBUG_ENTER("mysql_change_user"); if (!user) @@ -695,18 +696,26 @@ my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, /* Write authentication package */ simple_command(mysql,COM_CHANGE_USER, buff,(ulong) (end-buff),1); - if ((*mysql->methods->read_change_user_result)(mysql, buff, passwd)) - DBUG_RETURN(1); - /* Free old connect information */ - my_free(mysql->user,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->passwd,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->db,MYF(MY_ALLOW_ZERO_PTR)); - - /* alloc new connect information */ - mysql->user= my_strdup(user,MYF(MY_WME)); - mysql->passwd=my_strdup(passwd,MYF(MY_WME)); - mysql->db= db ? my_strdup(db,MYF(MY_WME)) : 0; - DBUG_RETURN(0); + rc= (*mysql->methods->read_change_user_result)(mysql, buff, passwd); + + /* + The server will close all statements no matter was the attempt + to change user successful or not. + */ + mysql_detach_stmt_list(&mysql->stmts); + if (rc == 0) + { + /* Free old connect information */ + my_free(mysql->user,MYF(MY_ALLOW_ZERO_PTR)); + my_free(mysql->passwd,MYF(MY_ALLOW_ZERO_PTR)); + my_free(mysql->db,MYF(MY_ALLOW_ZERO_PTR)); + + /* alloc new connect information */ + mysql->user= my_strdup(user,MYF(MY_WME)); + mysql->passwd=my_strdup(passwd,MYF(MY_WME)); + mysql->db= db ? my_strdup(db,MYF(MY_WME)) : 0; + } + DBUG_RETURN(rc); } #if defined(HAVE_GETPWUID) && defined(NO_GETPWUID_DECL) |