aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2006-11-21 22:35:29 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2006-11-21 22:35:29 +0000
commit7ec1c5a867d391a8d2778a9f6a05083fb9acb5f4 (patch)
tree133b314d2505cfdd6abbbfca7022451eb100b04a /src/backend/executor
parent5fc2d7e45148b92ea082356b425562c3cb971954 (diff)
downloadpostgresql-7ec1c5a867d391a8d2778a9f6a05083fb9acb5f4.tar.gz
postgresql-7ec1c5a867d391a8d2778a9f6a05083fb9acb5f4.zip
Prevent intratransaction memory leak when a subtransaction is aborted
in the middle of executing a SPI query. This doesn't entirely fix the problem of memory leakage in plpgsql exception handling, but it should get rid of the lion's share of leakage.
Diffstat (limited to 'src/backend/executor')
-rw-r--r--src/backend/executor/spi.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c
index 5410c364e0a..d4fa794bc3d 100644
--- a/src/backend/executor/spi.c
+++ b/src/backend/executor/spi.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.164 2006/10/04 00:29:53 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.165 2006/11/21 22:35:29 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -254,6 +254,19 @@ AtEOSubXact_SPI(bool isCommit, SubTransactionId mySubid)
(errcode(ERRCODE_WARNING),
errmsg("subtransaction left non-empty SPI stack"),
errhint("Check for missing \"SPI_finish\" calls.")));
+
+ /*
+ * If we are aborting a subtransaction and there is an open SPI context
+ * surrounding the subxact, clean up to prevent memory leakage.
+ */
+ if (_SPI_current && !isCommit)
+ {
+ /* free Executor memory the same as _SPI_end_call would do */
+ MemoryContextResetAndDeleteChildren(_SPI_current->execCxt);
+ /* throw away any partially created tuple-table */
+ SPI_freetuptable(_SPI_current->tuptable);
+ _SPI_current->tuptable = NULL;
+ }
}