Skip to content

Commit

Permalink
MDEV-33767: Memory leaks found in some tests run with --ps-protocol a…
Browse files Browse the repository at this point in the history
…gainst a server built with the option -DWITH_PROTECT_STATEMENT_MEMROOT

Found memory leaks were introduced by the commit
  a896beb
  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.
  • Loading branch information
dmitryshulga committed Mar 28, 2024
1 parent 9f1019b commit f44e41d
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions sql/sql_union.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit f44e41d

Please sign in to comment.