Skip to content

Commit a1c2c43

Browse files
committed
Fix intra-query memory leakage in nodeProjectSet.c.
Both ExecMakeFunctionResultSet() and evaluation of simple expressions need to be done in the per-tuple memory context, not per-query, else we leak data until end of query. This is a consideration that was missed while refactoring code in the ProjectSet patch (note that in pre-v10, ExecMakeFunctionResult is called in the per-tuple context). Per bug #14843 from Ben M. Diagnosed independently by Andres and myself. Discussion: https://postgr.es/m/20171005230321.28561.15927@wrigleys.postgresql.org
1 parent 6b87416 commit a1c2c43

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/backend/executor/execSRF.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,8 @@ ExecInitFunctionResultSet(Expr *expr,
467467
* function itself. The argument expressions may not contain set-returning
468468
* functions (the planner is supposed to have separated evaluation for those).
469469
*
470+
* This should be called in a short-lived (per-tuple) context.
471+
*
470472
* This is used by nodeProjectSet.c.
471473
*/
472474
Datum

src/backend/executor/nodeProjectSet.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,16 @@ ExecProjectSRF(ProjectSetState *node, bool continuing)
124124
{
125125
TupleTableSlot *resultSlot = node->ps.ps_ResultTupleSlot;
126126
ExprContext *econtext = node->ps.ps_ExprContext;
127+
MemoryContext oldcontext;
127128
bool hassrf PG_USED_FOR_ASSERTS_ONLY;
128129
bool hasresult;
129130
int argno;
130131

131132
ExecClearTuple(resultSlot);
132133

134+
/* Call SRFs, as well as plain expressions, in per-tuple context */
135+
oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
136+
133137
/*
134138
* Assume no further tuples are produced unless an ExprMultipleResult is
135139
* encountered from a set returning function.
@@ -176,6 +180,8 @@ ExecProjectSRF(ProjectSetState *node, bool continuing)
176180
}
177181
}
178182

183+
MemoryContextSwitchTo(oldcontext);
184+
179185
/* ProjectSet should not be used if there's no SRFs */
180186
Assert(hassrf);
181187

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy