aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/execGrouping.c
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2019-02-09 00:35:57 -0800
committerAndres Freund <andres@anarazel.de>2019-02-09 01:05:49 -0800
commit5567d12ce030781a4f749c9cd2034b95a3b64424 (patch)
treeb1c289a9822101c7a87e817b92652013aaa62bfe /src/backend/executor/execGrouping.c
parent0edef16d76beb8286cc832e4e1daf1f16b3d8f4a (diff)
downloadpostgresql-5567d12ce030781a4f749c9cd2034b95a3b64424.tar.gz
postgresql-5567d12ce030781a4f749c9cd2034b95a3b64424.zip
Plug leak in BuildTupleHashTable by creating ExprContext in correct context.
In bf6c614a2f2c5 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 bf6c614a2f2c5
Diffstat (limited to 'src/backend/executor/execGrouping.c')
-rw-r--r--src/backend/executor/execGrouping.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/backend/executor/execGrouping.c b/src/backend/executor/execGrouping.c
index 4e7600e4ed6..7cf001518a1 100644
--- a/src/backend/executor/execGrouping.c
+++ b/src/backend/executor/execGrouping.c
@@ -212,11 +212,17 @@ BuildTupleHashTable(PlanState *parent,
&TTSOpsMinimalTuple, &TTSOpsMinimalTuple,
numCols,
keyColIdx, eqfuncoids,
- parent);
+ NULL);
- MemoryContextSwitchTo(oldcontext);
+ /*
+ * While not pretty, it's ok to not shut down this context, but instead
+ * rely on the containing memory context being reset, as
+ * ExecBuildGroupingEqual() only builds a very simple expression calling
+ * functions (i.e. nothing that'd employ RegisterExprContextCallback()).
+ */
+ hashtable->exprcontext = CreateStandaloneExprContext();
- hashtable->exprcontext = CreateExprContext(parent->state);
+ MemoryContextSwitchTo(oldcontext);
return hashtable;
}