From 00ddc8bc7c003122bc424929f2a85872dbd8b813 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Tue, 9 Oct 2018 18:06:22 +0100 Subject: [PATCH] MDEV-17413 Crash in my_malloc_size_cb_func() during shutdown with forceful connection close. Fix is to ensure that when close_connection() is called from shutdown thread, current_thd is set. This that allocation callback for THD specific memory won't assert(in debug version), or crash (in 10.1 and later) close_connection() allocates THD specific memory e.g when it writes the final error packet, and compression is ON for the connection. --- sql/mysqld.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 9643f0699d1..6ac54d59ee4 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -1699,7 +1699,14 @@ static void close_connections(void) tmp->thread_id, (tmp->main_security_ctx.user ? tmp->main_security_ctx.user : "")); + /* + close_connection() might need a valid current_thd + for memory allocation tracking. + */ + THD* save_thd= current_thd; + set_current_thd(tmp); close_connection(tmp,ER_SERVER_SHUTDOWN); + set_current_thd(save_thd); } #endif DBUG_PRINT("quit",("Unlocking LOCK_thread_count"));