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 memory root for a 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 memory root was allocated and the pointer to
the original memory root was missed.
This commit is contained in:
Dmitry Shulga 2023-07-19 18:06:59 +07:00
parent 2086f96c6b
commit 6ac1d882a1
3 changed files with 12 additions and 7 deletions

View file

@ -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;
}

View file

@ -1061,7 +1061,7 @@ private:
~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)
{

View file

@ -9386,7 +9386,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);