Skip to content

Commit f44e41d

Browse files
committed
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 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.
1 parent 9f1019b commit f44e41d

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

sql/sql_union.cc

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,26 +1263,21 @@ bool st_select_lex_unit::join_union_item_types(THD *thd_arg,
12631263
}
12641264

12651265

1266-
bool init_item_int(THD* thd, Item_int* &item)
1266+
static bool init_item_int(THD* thd, Item_int* &item)
12671267
{
12681268
if (!item)
12691269
{
1270-
Query_arena *arena, backup_arena;
1271-
arena= thd->activate_stmt_arena_if_needed(&backup_arena);
1272-
12731270
item= new (thd->mem_root) Item_int(thd, 0);
12741271

1275-
if (arena)
1276-
thd->restore_active_arena(arena, &backup_arena);
1277-
12781272
if (!item)
1279-
return false;
1273+
return true;
12801274
}
12811275
else
12821276
{
12831277
item->value= 0;
12841278
}
1285-
return true;
1279+
1280+
return false;
12861281
}
12871282

12881283

@@ -1762,8 +1757,12 @@ bool st_select_lex_unit::prepare(TABLE_LIST *derived_arg,
17621757

17631758
for(uint i= 0; i< hidden; i++)
17641759
{
1765-
init_item_int(thd, addon_fields[i]);
1766-
types.push_front(addon_fields[i]);
1760+
if (init_item_int(thd, addon_fields[i]) ||
1761+
types.push_front(addon_fields[i]))
1762+
{
1763+
types.empty();
1764+
goto err;
1765+
}
17671766
addon_fields[i]->name.str= i ? "__CNT_1" : "__CNT_2";
17681767
addon_fields[i]->name.length= 7;
17691768
}

0 commit comments

Comments
 (0)