diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 1a32f37b139..932bb0c20ba 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -2046,6 +2046,16 @@ extern "C" void unireg_abort(int exit_code) mysqld_exit(exit_code); } + +static void cleanup_tls() +{ + if (THR_THD) + (void)pthread_key_delete(THR_THD); + if (THR_MALLOC) + (void)pthread_key_delete(THR_MALLOC); +} + + static void mysqld_exit(int exit_code) { DBUG_ENTER("mysqld_exit"); @@ -2064,6 +2074,7 @@ static void mysqld_exit(int exit_code) #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE shutdown_performance_schema(); // we do it as late as possible #endif + cleanup_tls(); DBUG_LEAVE; sd_notify(0, "STATUS=MariaDB server is down"); exit(exit_code); /* purecov: inspected */ @@ -2186,12 +2197,6 @@ void clean_up(bool print_message) #endif free_list(opt_plugin_load_list_ptr); - if (THR_THD) - (void) pthread_key_delete(THR_THD); - - if (THR_MALLOC) - (void) pthread_key_delete(THR_MALLOC); - /* The following lines may never be executed as the main thread may have killed us