diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index b6ad9fa2be3..8da2a257df7 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1989,6 +1989,11 @@ bool dispatch_command(enum enum_server_command command, THD *thd, dec_thread_running(); thd->packet.shrink(thd->variables.net_buffer_length); // Reclaim some memory thd->reset_kill_query(); /* Ensure that killed_errmsg is released */ + /* + LEX::m_sql_cmd can point to Sql_cmd allocated on thd->mem_root. + Unlink it now, before freeing the root. + */ + thd->lex->m_sql_cmd= NULL; free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC)); #if defined(ENABLED_PROFILING)