don't let current_thd to point to a destroyed THD

* reset current_thd in THD::~THD, otherwise my_malloc_size_cb_func()
  might access THD after it was destroyed.
* remove now redundant set_current_thd(0) calls that follow delete thd.
This commit is contained in:
Sergei Golubchik 2015-02-03 18:19:56 +01:00
parent d0fb9580e0
commit bfe703a458
11 changed files with 1 additions and 25 deletions

View file

@ -896,8 +896,6 @@ end:
delete scheduler;
}
delete thd;
/* Remember that we don't have a THD */
set_current_thd(0);
DBUG_RETURN(res);
}

View file

@ -2973,8 +2973,6 @@ bool one_thread_per_connection_end(THD *thd, bool put_in_cache)
const bool wsrep_applier= IF_WSREP(thd->wsrep_applier, false);
unlink_thd(thd);
/* Mark that current_thd is not valid anymore */
set_current_thd(0);
if (put_in_cache && cache_thread() && !wsrep_applier)
DBUG_RETURN(0); // Thread is reused
@ -6555,7 +6553,6 @@ void handle_connections_sockets()
(void) mysql_socket_close(new_sock);
}
delete thd;
set_current_thd(0);
statistic_increment(connection_errors_internal, &LOCK_status);
continue;
}
@ -6670,7 +6667,6 @@ pthread_handler_t handle_connections_namedpipes(void *arg)
{
close_connection(thd, ER_OUT_OF_RESOURCES);
delete thd;
set_current_thd(0);
continue;
}
/* Host is unknown */

View file

@ -1140,8 +1140,6 @@ bool acl_init(bool dont_read_acl_tables)
*/
return_val= acl_reload(thd);
delete thd;
/* Remember that we don't have a THD */
set_current_thd(0);
DBUG_RETURN(return_val);
}
@ -6556,8 +6554,6 @@ bool grant_init()
thd->store_globals();
return_val= grant_reload(thd);
delete thd;
/* Remember that we don't have a THD */
set_current_thd(0);
DBUG_RETURN(return_val);
}

View file

@ -9024,7 +9024,6 @@ my_bool mysql_rm_tmp_tables(void)
my_dirend(dirp);
}
delete thd;
set_current_thd(0);
DBUG_RETURN(0);
}

View file

@ -1712,7 +1712,7 @@ THD::~THD()
DBUG_ASSERT(status_var.local_memory_used == 0);
}
set_current_thd(orig_thd);
set_current_thd(orig_thd == this ? 0 : orig_thd);
DBUG_VOID_RETURN;
}

View file

@ -1775,7 +1775,6 @@ static void plugin_load(MEM_ROOT *tmp_root)
end:
/* Remember that we don't have a THD */
delete new_thd;
set_current_thd(0);
DBUG_VOID_RETURN;
}

View file

@ -98,8 +98,6 @@ bool reload_acl_and_cache(THD *thd, unsigned long long options,
if (tmp_thd)
{
delete tmp_thd;
/* Remember that we don't have a THD */
set_current_thd(0);
thd= 0;
}
reset_mqh((LEX_USER *)NULL, TRUE);

View file

@ -173,8 +173,6 @@ bool servers_init(bool dont_read_servers_table)
*/
return_val= servers_reload(thd);
delete thd;
/* Remember that we don't have a THD */
set_current_thd(0);
end:
DBUG_RETURN(return_val);

View file

@ -1674,8 +1674,6 @@ void execute_ddl_log_recovery()
global_ddl_log.recovery_phase= FALSE;
mysql_mutex_unlock(&LOCK_gdl);
delete thd;
/* Remember that we don't have a THD */
set_current_thd(0);
DBUG_VOID_RETURN;
}

View file

@ -258,8 +258,6 @@ void udf_init()
end:
close_mysql_tables(new_thd);
delete new_thd;
/* Remember that we don't have a THD */
set_current_thd(0);
DBUG_VOID_RETURN;
}

View file

@ -1803,11 +1803,7 @@ end:
if (org_thd)
org_thd->store_globals(); /* purecov: inspected */
else
{
/* Remember that we don't have a THD */
set_current_thd(0);
my_pthread_setspecific_ptr(THR_MALLOC, 0);
}
default_tz= default_tz_name ? global_system_variables.time_zone
: my_tz_SYSTEM;