Commit 2c1345ab authored by Rex's avatar Rex Committed by Daniel Black

MDEV-31995 Fix2 allocate memory in mem_root properly.

Lex_ident_sys had no new operator and was used incorrectly in
save_item_list_names(), so leaked memory.
parent 36680b64
...@@ -10697,8 +10697,9 @@ bool st_select_lex::save_item_list_names(THD *thd) ...@@ -10697,8 +10697,9 @@ bool st_select_lex::save_item_list_names(THD *thd)
while ((item= li++)) while ((item= li++))
{ {
if (unlikely(orig_names_of_item_list_elems->push_back( Lex_ident_sys *name= new (thd->mem_root) Lex_ident_sys(thd, &item->name);
new Lex_ident_sys(item->name.str, item->name.length), thd->mem_root))) if (unlikely(!name ||
orig_names_of_item_list_elems->push_back(name, thd->mem_root)))
{ {
if (arena) if (arena)
thd->restore_active_arena(arena, &backup); thd->restore_active_arena(arena, &backup);
......
...@@ -143,6 +143,11 @@ class Lex_ident_cli: public Lex_ident_cli_st ...@@ -143,6 +143,11 @@ class Lex_ident_cli: public Lex_ident_cli_st
struct Lex_ident_sys_st: public LEX_CSTRING struct Lex_ident_sys_st: public LEX_CSTRING
{ {
public: public:
static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
{ return alloc_root(mem_root, size); }
static void operator delete(void *ptr,size_t size) { TRASH_FREE(ptr, size); }
static void operator delete(void *ptr, MEM_ROOT *mem_root) {}
bool copy_ident_cli(THD *thd, const Lex_ident_cli_st *str); bool copy_ident_cli(THD *thd, const Lex_ident_cli_st *str);
bool copy_keyword(THD *thd, const Lex_ident_cli_st *str); bool copy_keyword(THD *thd, const Lex_ident_cli_st *str);
bool copy_sys(THD *thd, const LEX_CSTRING *str); bool copy_sys(THD *thd, const LEX_CSTRING *str);
...@@ -176,6 +181,10 @@ class Lex_ident_sys: public Lex_ident_sys_st ...@@ -176,6 +181,10 @@ class Lex_ident_sys: public Lex_ident_sys_st
LEX_CSTRING tmp= {name, length}; LEX_CSTRING tmp= {name, length};
set_valid_utf8(&tmp); set_valid_utf8(&tmp);
} }
Lex_ident_sys(THD *thd, const LEX_CSTRING *str)
{
set_valid_utf8(str);
}
Lex_ident_sys & operator=(const Lex_ident_sys_st &name) Lex_ident_sys & operator=(const Lex_ident_sys_st &name)
{ {
Lex_ident_sys_st::operator=(name); Lex_ident_sys_st::operator=(name);
......
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