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
  a896bebfa6
  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.
This commit is contained in:
Dmitry Shulga 2024-03-27 22:55:15 +07:00
parent 9f1019ba3d
commit f44e41db38

View file

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