Commit 5c4122d3 authored by pem@mysql.com's avatar pem@mysql.com

Fixed the last memory leaks in the SP code.

parent 1fc3582b
...@@ -373,13 +373,11 @@ sp_cache_functions(THD *thd, LEX *lex) ...@@ -373,13 +373,11 @@ sp_cache_functions(THD *thd, LEX *lex)
void void
sp_clear_function_cache(THD *thd) sp_clear_function_cache(THD *thd)
{ {
//QQ This doesn't work for some completely mysterious reason, but since this List_iterator_fast<sp_head> li(thd->spfuns);
//QQ is tempoarary code anyway, we just ignore it for now. sp_head *sp;
//QQ List_iterator_fast<sp_head> li(thd->spfuns);
//QQ sp_head *sp;
//QQ while ((sp= li++)) while ((sp= li++))
//QQ sp->destroy(); sp->destroy();
thd->spfuns.empty(); thd->spfuns.empty();
} }
......
...@@ -94,8 +94,10 @@ eval_func_item(THD *thd, Item *it, enum enum_field_types type) ...@@ -94,8 +94,10 @@ eval_func_item(THD *thd, Item *it, enum enum_field_types type)
sp_head::sp_head(LEX_STRING *name, LEX *lex) sp_head::sp_head(LEX_STRING *name, LEX *lex)
: Sql_alloc(), m_simple_case(FALSE) : Sql_alloc(), m_simple_case(FALSE)
{ {
DBUG_ENTER("sp_head::sp_head");
const char *dstr = (const char*)lex->buf; const char *dstr = (const char*)lex->buf;
DBUG_PRINT("info", ("name: %s", name->str));
m_name.length= name->length; m_name.length= name->length;
m_name.str= name->str; m_name.str= name->str;
m_defstr.length= lex->end_of_query - lex->buf; m_defstr.length= lex->end_of_query - lex->buf;
...@@ -103,6 +105,7 @@ sp_head::sp_head(LEX_STRING *name, LEX *lex) ...@@ -103,6 +105,7 @@ sp_head::sp_head(LEX_STRING *name, LEX *lex)
m_pcont= lex->spcont; m_pcont= lex->spcont;
my_init_dynamic_array(&m_instr, sizeof(sp_instr *), 16, 8); my_init_dynamic_array(&m_instr, sizeof(sp_instr *), 16, 8);
m_backpatch.empty(); m_backpatch.empty();
DBUG_VOID_RETURN;
} }
int int
...@@ -128,8 +131,11 @@ sp_head::create(THD *thd) ...@@ -128,8 +131,11 @@ sp_head::create(THD *thd)
void void
sp_head::destroy() sp_head::destroy()
{ {
DBUG_ENTER("sp_head::destroy");
DBUG_PRINT("info", ("name: %s", m_name.str));
delete_dynamic(&m_instr); delete_dynamic(&m_instr);
m_pcont->destroy(); m_pcont->destroy();
DBUG_VOID_RETURN;
} }
int int
......
...@@ -1523,6 +1523,14 @@ restore_user: ...@@ -1523,6 +1523,14 @@ restore_user:
thread_running--; thread_running--;
VOID(pthread_mutex_unlock(&LOCK_thread_count)); VOID(pthread_mutex_unlock(&LOCK_thread_count));
thd->packet.shrink(thd->variables.net_buffer_length); // Reclaim some memory thd->packet.shrink(thd->variables.net_buffer_length); // Reclaim some memory
/*
Clear the SP function cache after each statement (QQ this is a temporary
solution; caching will be rehacked later).
Note: Must do this before we free_root.
*/
sp_clear_function_cache(thd);
free_root(&thd->mem_root,MYF(MY_KEEP_PREALLOC)); free_root(&thd->mem_root,MYF(MY_KEEP_PREALLOC));
DBUG_RETURN(error); DBUG_RETURN(error);
} }
...@@ -1587,11 +1595,6 @@ mysql_execute_command(THD *thd) ...@@ -1587,11 +1595,6 @@ mysql_execute_command(THD *thd)
SELECT_LEX_UNIT *unit= &lex->unit; SELECT_LEX_UNIT *unit= &lex->unit;
DBUG_ENTER("mysql_execute_command"); DBUG_ENTER("mysql_execute_command");
/*
Clear the SP function cache before each statement (QQ this is a temporary
solution; caching will be rehacked later), and the new ones.
*/
sp_clear_function_cache(thd);
if (lex->sql_command != SQLCOM_CREATE_PROCEDURE && if (lex->sql_command != SQLCOM_CREATE_PROCEDURE &&
lex->sql_command != SQLCOM_CREATE_SPFUNCTION) lex->sql_command != SQLCOM_CREATE_SPFUNCTION)
{ {
...@@ -3009,6 +3012,9 @@ mysql_execute_command(THD *thd) ...@@ -3009,6 +3012,9 @@ mysql_execute_command(THD *thd)
} }
#endif #endif
res= lex->sphead->create(thd); res= lex->sphead->create(thd);
lex->sphead->destroy(); // QQ Free memory. Remove this when caching!!!
switch (res) switch (res)
{ {
case SP_OK: case SP_OK:
......
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