More paranoia in AtEOSubXact_SPI: don't assume we can safely use SPI_finish

for cleaning up.  It seems possible that the memory contexts SPI_finish
would try to touch are already gone; and there's no need for SPI itself
to delete them, since the containing contexts will surely be going away
anyway at transaction end.
This commit is contained in:
Tom Lane 2004-07-01 21:17:13 +00:00
parent 1732cb0dbe
commit 25ee160acd
1 changed files with 16 additions and 5 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.119 2004/07/01 00:50:26 tgl Exp $
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.120 2004/07/01 21:17:13 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -206,16 +206,27 @@ AtEOSubXact_SPI(bool isCommit, TransactionId childXid)
while (_SPI_connected >= 0)
{
_SPI_connection *connection = &(_SPI_stack[_SPI_connected]);
int res;
if (connection->connectXid != childXid)
break; /* couldn't be any underneath it either */
found = true;
_SPI_curid = _SPI_connected - 1; /* avoid begin_call error */
res = SPI_finish();
Assert(res == SPI_OK_FINISH);
/*
* Pop the stack entry and reset global variables. Unlike
* SPI_finish(), we don't risk switching to memory contexts that
* might be already gone, or deleting memory contexts that have been
* or will be thrown away anyway.
*/
_SPI_connected--;
_SPI_curid = _SPI_connected;
if (_SPI_connected == -1)
_SPI_current = NULL;
else
_SPI_current = &(_SPI_stack[_SPI_connected]);
SPI_processed = 0;
SPI_lastoid = InvalidOid;
SPI_tuptable = NULL;
}
if (found && isCommit)