diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 12f0cc4ca72..60220ffc889 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -336,6 +336,8 @@ THD::~THD() #ifndef DBUG_OFF dbug_sentry = THD_SENTRY_GONE; #endif + /* Reset stmt_backup.mem_root to not double-free memory from thd.mem_root */ + init_alloc_root(&stmt_backup.mem_root, 0, 0); DBUG_VOID_RETURN; } diff --git a/sql/sql_class.h b/sql/sql_class.h index c1cd65edf76..5390e8a4ac4 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -582,8 +582,7 @@ public: Statement_map stmt_map; /* keeps THD state while it is used for active statement - Note, that double free_root() is safe, so we don't need to do any - special cleanup for it in THD destructor. + Note: we perform special cleanup for it in THD destructor. */ Statement stmt_backup; /*