Commit f44e41db authored by Dmitry Shulga's avatar Dmitry Shulga

MDEV-33767: Memory leaks found in some tests run with --ps-protocol against a...

MDEV-33767: Memory leaks found in some tests run with --ps-protocol against a server built with the option -DWITH_PROTECT_STATEMENT_MEMROOT

Found memory leaks were introduced by the commit
  a896bebf
  MDEV-18844 Implement EXCEPT ALL and INTERSECT ALL operations
and caused by using a statement arena instead a runtime arena for
allocation of objects having temporary life span by their nature.
Aforementioned memory leaks were produced by running queries
that typically use select with intersect, union or table values
constructors.

To fix these memory leaks use the runtime arena for allocation
of Item_field objects used by set operations.

Additionally, OOM handling added on allocation of aforementioned
Item_field objects.
parent 9f1019ba
......@@ -1263,26 +1263,21 @@ bool st_select_lex_unit::join_union_item_types(THD *thd_arg,
}
bool init_item_int(THD* thd, Item_int* &item)
static bool init_item_int(THD* thd, Item_int* &item)
{
if (!item)
{
Query_arena *arena, backup_arena;
arena= thd->activate_stmt_arena_if_needed(&backup_arena);
item= new (thd->mem_root) Item_int(thd, 0);
if (arena)
thd->restore_active_arena(arena, &backup_arena);
if (!item)
return false;
return true;
}
else
{
item->value= 0;
}
return true;
return false;
}
......@@ -1762,8 +1757,12 @@ bool st_select_lex_unit::prepare(TABLE_LIST *derived_arg,
for(uint i= 0; i< hidden; i++)
{
init_item_int(thd, addon_fields[i]);
types.push_front(addon_fields[i]);
if (init_item_int(thd, addon_fields[i]) ||
types.push_front(addon_fields[i]))
{
types.empty();
goto err;
}
addon_fields[i]->name.str= i ? "__CNT_1" : "__CNT_2";
addon_fields[i]->name.length= 7;
}
......
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