Commit 8eb903e1 authored by Dmitry Shulga's avatar Dmitry Shulga

MDEV-5816: Stored programs: validation of stored program statements

Fixed memory leakage taken place on execution of the statement
  SHOW CREATE PACKAGE pkg_name
The memory leak was caused by implementation of sp_compile()
where a mempory root for stored routine was allocated but
a pointer to the new memory root wasn't passed to sp_package::create
for subsequent forwarding to the constructor of sp_package.
Instead, another one mempory root was allocated and the pointer to
the original memroot was missed.
parent 304e491e
......@@ -607,14 +607,18 @@ sp_head::sp_head(MEM_ROOT *mem_root_arg, sp_package *parent,
sp_package *sp_package::create(LEX *top_level_lex, const sp_name *name,
const Sp_handler *sph)
const Sp_handler *sph, MEM_ROOT *sp_mem_root)
{
MEM_ROOT own_root;
init_sql_alloc(key_memory_sp_head_main_root, &own_root, MEM_ROOT_BLOCK_SIZE,
MEM_ROOT_PREALLOC, MYF(0));
if (!sp_mem_root)
{
init_sql_alloc(key_memory_sp_head_main_root, &own_root, MEM_ROOT_BLOCK_SIZE,
MEM_ROOT_PREALLOC, MYF(0));
sp_mem_root= &own_root;
}
sp_package *sp;
if (!(sp= new (&own_root) sp_package(&own_root, top_level_lex, name, sph)))
free_root(&own_root, MYF(0));
if (!(sp= new (sp_mem_root) sp_package(sp_mem_root, top_level_lex, name, sph)))
free_root(sp_mem_root, MYF(0));
return sp;
}
......
......@@ -1062,7 +1062,7 @@ class sp_package: public sp_head
~sp_package();
public:
static sp_package *create(LEX *top_level_lex, const sp_name *name,
const Sp_handler *sph);
const Sp_handler *sph, MEM_ROOT *sp_mem_root);
bool add_routine_declaration(LEX *lex)
{
......
......@@ -9397,7 +9397,8 @@ sp_package *LEX::create_package_start(THD *thd,
return 0;
}
}
if (unlikely(!(pkg= sp_package::create(this, name_arg, sph))))
if (unlikely(!(pkg= sp_package::create(this, name_arg, sph,
sp_mem_root_ptr))))
return NULL;
pkg->reset_thd_mem_root(thd);
pkg->init(this);
......
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