WL#2936

  Move copying of global variables into thd.variables into plugin_thdvar_init().
  plugin_thdvar_init() may be called multiple times when THD::change_user() is called.
  This fixes a plugin ref-count leak when running the test mysql_client_test
parent a57260db
...@@ -345,6 +345,7 @@ THD::THD() ...@@ -345,6 +345,7 @@ THD::THD()
time_after_lock=(time_t) 0; time_after_lock=(time_t) 0;
current_linfo = 0; current_linfo = 0;
slave_thread = 0; slave_thread = 0;
bzero(&variables, sizeof(variables));
thread_id= variables.pseudo_thread_id= 0; thread_id= variables.pseudo_thread_id= 0;
one_shot_set= 0; one_shot_set= 0;
file_id = 0; file_id = 0;
...@@ -455,8 +456,6 @@ void THD::pop_internal_handler() ...@@ -455,8 +456,6 @@ void THD::pop_internal_handler()
void THD::init(void) void THD::init(void)
{ {
pthread_mutex_lock(&LOCK_global_system_variables); pthread_mutex_lock(&LOCK_global_system_variables);
variables= global_system_variables;
variables.table_plugin= NULL;
plugin_thdvar_init(this); plugin_thdvar_init(this);
variables.time_format= date_time_format_copy((THD*) 0, variables.time_format= date_time_format_copy((THD*) 0,
variables.time_format); variables.time_format);
......
...@@ -2303,14 +2303,26 @@ static byte *mysql_sys_var_ptr(void* a_thd, int offset) ...@@ -2303,14 +2303,26 @@ static byte *mysql_sys_var_ptr(void* a_thd, int offset)
void plugin_thdvar_init(THD *thd) void plugin_thdvar_init(THD *thd)
{ {
plugin_ref old_table_plugin= thd->variables.table_plugin;
DBUG_ENTER("plugin_thdvar_init");
thd->variables.table_plugin= NULL;
cleanup_variables(thd, &thd->variables);
thd->variables= global_system_variables;
thd->variables.table_plugin= NULL;
/* we are going to allocate these lazily */ /* we are going to allocate these lazily */
thd->variables.dynamic_variables_version= 0; thd->variables.dynamic_variables_version= 0;
thd->variables.dynamic_variables_size= 0; thd->variables.dynamic_variables_size= 0;
thd->variables.dynamic_variables_ptr= 0; thd->variables.dynamic_variables_ptr= 0;
DBUG_ASSERT(!(thd->variables.table_plugin)); pthread_mutex_lock(&LOCK_plugin);
thd->variables.table_plugin= thd->variables.table_plugin=
my_plugin_lock(NULL, &global_system_variables.table_plugin); my_intern_plugin_lock(NULL, global_system_variables.table_plugin);
intern_plugin_unlock(NULL, old_table_plugin);
pthread_mutex_unlock(&LOCK_plugin);
DBUG_VOID_RETURN;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment