Skip to content

Commit 5567d12

Browse files
committed
Plug leak in BuildTupleHashTable by creating ExprContext in correct context.
In bf6c614 I added a expr context to evaluate the grouping expression. Unfortunately the code I added initialized them while in the calling context, rather the table context. Additionally, I used CreateExprContext() rather than CreateStandaloneExprContext(), which creates the econtext in the estate's query context. Fix that by using CreateStandaloneExprContext when in the table's tablecxt. As we rely on the memory being freed by a memory context reset that means that the econtext's shutdown callbacks aren't being called, but that seems ok as the expressions are tightly controlled due to ExecBuildGroupingEqual(). Bug: #15592 Reported-By: Dmitry Marakasov Author: Andres Freund Discussion: https://postgr.es/m/20190114222838.h6r3fuyxjxkykf6t@alap3.anarazel.de Backpatch: 11, where I broke this in bf6c614
1 parent 0edef16 commit 5567d12

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/backend/executor/execGrouping.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,17 @@ BuildTupleHashTable(PlanState *parent,
212212
&TTSOpsMinimalTuple, &TTSOpsMinimalTuple,
213213
numCols,
214214
keyColIdx, eqfuncoids,
215-
parent);
215+
NULL);
216216

217-
MemoryContextSwitchTo(oldcontext);
217+
/*
218+
* While not pretty, it's ok to not shut down this context, but instead
219+
* rely on the containing memory context being reset, as
220+
* ExecBuildGroupingEqual() only builds a very simple expression calling
221+
* functions (i.e. nothing that'd employ RegisterExprContextCallback()).
222+
*/
223+
hashtable->exprcontext = CreateStandaloneExprContext();
218224

219-
hashtable->exprcontext = CreateExprContext(parent->state);
225+
MemoryContextSwitchTo(oldcontext);
220226

221227
return hashtable;
222228
}

0 commit comments

Comments
 (0)