Skip to content

Commit 7ec1c5a

Browse files
committed
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.
1 parent 5fc2d7e commit 7ec1c5a

File tree

1 file changed

+14
-1
lines changed
  • src/backend/executor

1 file changed

+14
-1
lines changed

src/backend/executor/spi.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.164 2006/10/04 00:29:53 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.165 2006/11/21 22:35:29 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -254,6 +254,19 @@ AtEOSubXact_SPI(bool isCommit, SubTransactionId mySubid)
254254
(errcode(ERRCODE_WARNING),
255255
errmsg("subtransaction left non-empty SPI stack"),
256256
errhint("Check for missing \"SPI_finish\" calls.")));
257+
258+
/*
259+
* If we are aborting a subtransaction and there is an open SPI context
260+
* surrounding the subxact, clean up to prevent memory leakage.
261+
*/
262+
if (_SPI_current && !isCommit)
263+
{
264+
/* free Executor memory the same as _SPI_end_call would do */
265+
MemoryContextResetAndDeleteChildren(_SPI_current->execCxt);
266+
/* throw away any partially created tuple-table */
267+
SPI_freetuptable(_SPI_current->tuptable);
268+
_SPI_current->tuptable = NULL;
269+
}
257270
}
258271

259272

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