From 08b0b70daa43a539d911238e25998f7450bab9e6 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Tue, 24 Nov 2020 08:45:04 +0100 Subject: [PATCH] MDEV-24084 Fix race between disconnect and KILL CONNECTION Prior to this patch, it is possible to access freed memory (THD::event_scheduler) from tp_post_kill_notification(). With this patch, memory is freed only when THD is no more accessible from other threads, i.e after it is removed from the thread_list. --- sql/threadpool_common.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sql/threadpool_common.cc b/sql/threadpool_common.cc index 03c39d65f231b..7de7866e01556 100644 --- a/sql/threadpool_common.cc +++ b/sql/threadpool_common.cc @@ -202,12 +202,11 @@ void tp_callback(TP_connection *c) error: c->thd= 0; - delete c; - if (thd) { threadpool_remove_connection(thd); } + delete c; worker_context.restore(); }