mirror of
https://github.com/MariaDB/server.git
synced 2025-07-27 18:02:13 +03:00
Bug#30882 Dropping a temporary table inside a stored function may cause a server crash
If a stored function that contains a drop temporary table statement is invoked by a create temporary table of the same name may cause a server crash. The problem is that when dropping a table no check is done to ensure that table is not being used by some outer query (or outer statement), potentially leaving the outer query with a reference to a stale (freed) table. The solution is when dropping a temporary table, always check if the table is being used by some outer statement as a temporary table can be dropped inside stored procedures. The check is performed by looking at the TABLE::query_id value for temporary tables. To simplify this check and to solve a bug related to handling of temporary tables in prelocked mode, this patch changes the way in which this member is used to track the fact that table is used/unused. Now we ensure that TABLE::query_id is zero for unused temporary tables (which means that all temporary tables which were used by a statement should be marked as free for reuse after it's execution has been completed).
This commit is contained in:
@ -679,7 +679,7 @@ extern my_decimal decimal_zero;
|
||||
void free_items(Item *item);
|
||||
void cleanup_items(Item *item);
|
||||
class THD;
|
||||
void close_thread_tables(THD *thd, bool locked=0, bool skip_derived=0);
|
||||
void close_thread_tables(THD *thd);
|
||||
bool check_one_table_access(THD *thd, ulong privilege, TABLE_LIST *tables);
|
||||
bool check_single_table_access(THD *thd, ulong privilege,
|
||||
TABLE_LIST *tables, bool no_errors);
|
||||
@ -1419,7 +1419,7 @@ TABLE_LIST *unique_table(THD *thd, TABLE_LIST *table, TABLE_LIST *table_list,
|
||||
bool check_alias);
|
||||
TABLE *find_temporary_table(THD *thd, const char *db, const char *table_name);
|
||||
TABLE *find_temporary_table(THD *thd, TABLE_LIST *table_list);
|
||||
bool close_temporary_table(THD *thd, TABLE_LIST *table_list);
|
||||
int drop_temporary_table(THD *thd, TABLE_LIST *table_list);
|
||||
void close_temporary_table(THD *thd, TABLE *table, bool free_share,
|
||||
bool delete_table);
|
||||
void close_temporary(TABLE *table, bool free_share, bool delete_table);
|
||||
|
Reference in New Issue
Block a user