]> granicus.if.org Git - postgresql/commitdiff
More paranoia in AtEOSubXact_SPI: don't assume we can safely use SPI_finish
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 1 Jul 2004 21:17:13 +0000 (21:17 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 1 Jul 2004 21:17:13 +0000 (21:17 +0000)
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.

src/backend/executor/spi.c

index 7534ddd793388818f06a848244f7709492242157..19dbfc13d0f3b9ece13cfdf503886d42a80f844b 100644 (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)