From 838b5378cb1998b27b106273f5e9043838888d39 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 27 Nov 2006 13:24:24 +0400 Subject: Fix for bug #21587: FLUSH TABLES causes server crash when used with HANDLER statements Problems (appear only under some circumstances): 1. we get a reference to a deleted table searching in the thd->handler_tables_hash in the mysql_ha_read(). 2. DBUG_ASSERT(table->file->inited == handler::NONE); assert fails in the close_thread_table(). Fix: end open index scans and table scans and remove references to the tables from the handler tables hash. After this preparation it is safe to close the tables. The close can no longer fail on open index/table scans and the closed table will not be used again by handler functions. sql/mysql_priv.h: Fix for bug #21587: FLUSH TABLES causes server crash when used with HANDLER statements - mysql_ha_mark_tables_for_reopen() introduced. sql/sql_base.cc: Fix for bug #21587: FLUSH TABLES causes server crash when used with HANDLER statements - call mysql_ha_mark_tables_for_reopen() to prepare for the following close. sql/sql_handler.cc: Fix for bug #21587: FLUSH TABLES causes server crash when used with HANDLER statements - mysql_ha_mark_tables_for_reopen() function introduced. --- sql/sql_base.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'sql/sql_base.cc') diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 0f6715fc078..053f6fcb845 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -519,7 +519,15 @@ void close_thread_tables(THD *thd, bool lock_in_use, bool skip_derived) DBUG_PRINT("info", ("thd->open_tables: %p", thd->open_tables)); - found_old_table= 0; + + /* + End open index scans and table scans and remove references to the tables + from the handler tables hash. After this preparation it is safe to close + the tables. + */ + mysql_ha_mark_tables_for_reopen(thd, thd->open_tables); + + found_old_table= 0; while (thd->open_tables) found_old_table|=close_thread_table(thd, &thd->open_tables); thd->some_tables_deleted=0; -- cgit v1.2.1