diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2001-01-22 00:50:07 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2001-01-22 00:50:07 +0000 |
commit | c9fe12831632efc437354cb0482fd6cb5f246a4a (patch) | |
tree | b9b19b88a07ebfd51915b60bc492bfe68c6cd732 /src/backend/executor/execUtils.c | |
parent | 59a3a401497cd72c550fdfcaa782162d91335bba (diff) | |
download | postgresql-c9fe12831632efc437354cb0482fd6cb5f246a4a.tar.gz postgresql-c9fe12831632efc437354cb0482fd6cb5f246a4a.zip |
Clean up per-tuple memory leaks in trigger firing and plpgsql
expression evaluation.
Diffstat (limited to 'src/backend/executor/execUtils.c')
-rw-r--r-- | src/backend/executor/execUtils.c | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/src/backend/executor/execUtils.c b/src/backend/executor/execUtils.c index 5d4d7f145b3..a4c7143aa77 100644 --- a/src/backend/executor/execUtils.c +++ b/src/backend/executor/execUtils.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.70 2000/12/27 23:59:11 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.71 2001/01/22 00:50:07 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -230,6 +230,26 @@ FreeExprContext(ExprContext *econtext) pfree(econtext); } +/* + * Build a per-output-tuple ExprContext for an EState. + * + * This is normally invoked via GetPerTupleExprContext() macro. + */ +ExprContext * +MakePerTupleExprContext(EState *estate) +{ + if (estate->es_per_tuple_exprcontext == NULL) + { + MemoryContext oldContext; + + oldContext = MemoryContextSwitchTo(estate->es_query_cxt); + estate->es_per_tuple_exprcontext = + MakeExprContext(NULL, estate->es_query_cxt); + MemoryContextSwitchTo(oldContext); + } + return estate->es_per_tuple_exprcontext; +} + /* ---------------------------------------------------------------- * Result slot tuple type and ProjectionInfo support * ---------------------------------------------------------------- @@ -836,21 +856,9 @@ ExecInsertIndexTuples(TupleTableSlot *slot, /* * We will use the EState's per-tuple context for evaluating predicates - * and functional-index functions. Create it if it's not already there; - * if it is, reset it to free previously-used storage. + * and functional-index functions (creating it if it's not already there). */ - econtext = estate->es_per_tuple_exprcontext; - if (econtext == NULL) - { - MemoryContext oldContext; - - oldContext = MemoryContextSwitchTo(estate->es_query_cxt); - estate->es_per_tuple_exprcontext = econtext = - MakeExprContext(NULL, estate->es_query_cxt); - MemoryContextSwitchTo(oldContext); - } - else - ResetExprContext(econtext); + econtext = GetPerTupleExprContext(estate); /* Arrange for econtext's scan tuple to be the tuple under test */ econtext->ecxt_scantuple = slot; |