diff options
author | Jon Olav Hauglid <jon.hauglid@oracle.com> | 2012-10-04 16:15:13 +0200 |
---|---|---|
committer | Jon Olav Hauglid <jon.hauglid@oracle.com> | 2012-10-04 16:15:13 +0200 |
commit | bfba296d4084eab4b580cddc04e889ad2abdaeb2 (patch) | |
tree | cfc04b7846d4672b0ec88a3d9e95830cfc41ff31 /sql/sp_rcontext.cc | |
parent | 30d35590a3bce929679cdc38d36fc67f7923a39e (diff) | |
download | mariadb-git-bfba296d4084eab4b580cddc04e889ad2abdaeb2.tar.gz |
Bug#14640599 MEMORY LEAK WHEN EXECUTING STORED ROUTINE EXCEPTION HANDLER
When a SP handler is activated, memory is allocated to hold the
MESSAGE_TEXT for the condition that caused the activation.
The problem was that this memory was allocated on the MEM_ROOT belonging
to the stored program. Since this MEM_ROOT is not freed until the
stored program ends, a stored program that causes lots of handler
activations can start using lots of memory. In 5.1 and earlier the
problem did not exist as no MESSAGE_TEXT was allocated if a condition
was raised with a handler present. However, this behavior lead to
a number of other issues such as Bug#23032.
This patch fixes the problem by allocating enough memory for the
necessary MESSAGE_TEXTs in the SP MEM_ROOT when the SP starts and
then re-using this memory each time a handler is activated.
This is the 5.5 version of the patch.
Diffstat (limited to 'sql/sp_rcontext.cc')
-rw-r--r-- | sql/sp_rcontext.cc | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/sql/sp_rcontext.cc b/sql/sp_rcontext.cc index fba6a56b37c..09f48d824b0 100644 --- a/sql/sp_rcontext.cc +++ b/sql/sp_rcontext.cc @@ -67,19 +67,15 @@ sp_rcontext::~sp_rcontext() bool sp_rcontext::init(THD *thd) { uint handler_count= m_root_parsing_ctx->max_handler_index(); - uint i; in_sub_stmt= thd->in_sub_stmt; if (init_var_table(thd) || init_var_items()) return TRUE; - if (!(m_raised_conditions= new (thd->mem_root) MYSQL_ERROR[handler_count])) + if (!(m_raised_conditions= new (thd->mem_root) Sql_condition_info[handler_count])) return TRUE; - for (i= 0; i<handler_count; i++) - m_raised_conditions[i].init(thd->mem_root); - return !(m_handler= (sp_handler_t*)thd->alloc(handler_count * sizeof(sp_handler_t))) || @@ -446,13 +442,12 @@ sp_rcontext::exit_handler() DBUG_VOID_RETURN; } -MYSQL_ERROR* -sp_rcontext::raised_condition() const +Sql_condition_info* sp_rcontext::raised_condition() const { if (m_ihsp > 0) { uint hindex= m_in_handler[m_ihsp - 1].index; - MYSQL_ERROR *raised= & m_raised_conditions[hindex]; + Sql_condition_info *raised= & m_raised_conditions[hindex]; return raised; } |