Content-Length: 292415 | pFad | https://github.com/postgrespro/postgres_cluster/commit/7ec1c5a867d391a8d2778a9f6a05083fb9acb5f4

65 Prevent intratransaction memory leak when a subtransaction is aborted · postgrespro/postgres_cluster@7ec1c5a · GitHub
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)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/postgrespro/postgres_cluster/commit/7ec1c5a867d391a8d2778a9f6a05083fb9acb5f4

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy