Commit 5f5f7bef authored by unknown's avatar unknown

MDEV-5356: Server crashes in Item_equal::contains on 2nd execution of a PS

THD::thd->activate_stmt_arena_if_needed() should be used to temporary activating statement arena instead of direct usage of THD::set_n_backup_active_arena() because possible such scenario:
  1) func1 saves current arena and activates copy1 of statement arena
  2) func2 saves copy1 of statement arena setup by func1 and activates copy2
  3) some changes made for copy 2
  4) func2 stores changed copy2 back to statenet arena and activates copy1
  5) func1 store unchanged copy1 back to statemnt arena (rewrite changed copy 2 so changes become lost) and activates arena which was before.
parent c0065d15
......@@ -7843,12 +7843,9 @@ bool setup_tables(THD *thd, Name_resolution_context *context,
{
DBUG_ASSERT(table_list->view &&
table_list->effective_algorithm == VIEW_ALGORITHM_MERGE);
Query_arena *arena= thd->stmt_arena, backup;
Query_arena *arena, backup;
arena= thd->activate_stmt_arena_if_needed(&backup);
bool res;
if (arena->is_conventional())
arena= 0; // For easier test
else
thd->set_n_backup_active_arena(arena, &backup);
res= table_list->setup_underlying(thd);
if (arena)
thd->restore_active_arena(arena, &backup);
......
......@@ -882,11 +882,8 @@ JOIN::optimize()
MEMROOT for prepared statements and stored procedures.
*/
Query_arena *arena= thd->stmt_arena, backup;
if (arena->is_conventional())
arena= 0; // For easier test
else
thd->set_n_backup_active_arena(arena, &backup);
Query_arena *arena, backup;
arena= thd->activate_stmt_arena_if_needed(&backup);
sel->first_cond_optimization= 0;
......
......@@ -1121,11 +1121,7 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table,
will be TRUE as far as we make new table cache).
*/
old_lex= thd->lex;
arena= thd->stmt_arena;
if (arena->is_conventional())
arena= 0;
else
thd->set_n_backup_active_arena(arena, &backup);
arena= thd->activate_stmt_arena_if_needed(&backup);
/* init timestamp */
if (!table->timestamp.str)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment