Skip to content

Commit e2605c8

Browse files
committed
Add a warning to AtEOXact_SPI() to catch cases where the current
transaction has been committed without SPI_finish() being called first. Per recent discussion here: http://archives.postgresql.org/pgsql-patches/2003-11/msg00286.php
1 parent 0fd336c commit e2605c8

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

src/backend/access/transam/xact.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.157 2003/11/29 19:51:40 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.158 2003/12/02 19:26:47 joe Exp $
1212
*
1313
* NOTES
1414
* Transaction aborts can now occur two ways:
@@ -977,7 +977,7 @@ CommitTransaction(void)
977977

978978
CallEOXactCallbacks(true);
979979
AtEOXact_GUC(true);
980-
AtEOXact_SPI();
980+
AtEOXact_SPI(true);
981981
AtEOXact_gist();
982982
AtEOXact_hash();
983983
AtEOXact_nbtree();
@@ -1087,7 +1087,7 @@ AbortTransaction(void)
10871087

10881088
CallEOXactCallbacks(false);
10891089
AtEOXact_GUC(false);
1090-
AtEOXact_SPI();
1090+
AtEOXact_SPI(false);
10911091
AtEOXact_gist();
10921092
AtEOXact_hash();
10931093
AtEOXact_nbtree();

src/backend/executor/spi.c

Lines changed: 12 additions & 4 deletions
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.108 2003/11/29 19:51:48 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.109 2003/12/02 19:26:47 joe Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -174,18 +174,26 @@ SPI_finish(void)
174174
}
175175

176176
/*
177-
* Clean up SPI state at transaction commit or abort (we don't care which).
177+
* Clean up SPI state at transaction commit or abort.
178178
*/
179179
void
180-
AtEOXact_SPI(void)
180+
AtEOXact_SPI(bool isCommit)
181181
{
182182
/*
183183
* Note that memory contexts belonging to SPI stack entries will be
184184
* freed automatically, so we can ignore them here. We just need to
185185
* restore our static variables to initial state.
186186
*/
187-
if (_SPI_stack != NULL) /* there was abort */
187+
if (_SPI_stack != NULL)
188+
{
188189
free(_SPI_stack);
190+
if (isCommit)
191+
ereport(WARNING,
192+
(errcode(ERRCODE_WARNING),
193+
errmsg("freeing non-empty SPI stack"),
194+
errhint("Check for missing \"SPI_finish\" calls")));
195+
}
196+
189197
_SPI_current = _SPI_stack = NULL;
190198
_SPI_connected = _SPI_curid = -1;
191199
SPI_processed = 0;

src/include/executor/spi.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* spi.h
44
*
5-
* $PostgreSQL: pgsql/src/include/executor/spi.h,v 1.40 2003/11/29 22:41:01 pgsql Exp $
5+
* $PostgreSQL: pgsql/src/include/executor/spi.h,v 1.41 2003/12/02 19:26:47 joe Exp $
66
*
77
*-------------------------------------------------------------------------
88
*/
@@ -116,6 +116,6 @@ extern void SPI_cursor_fetch(Portal portal, bool forward, int count);
116116
extern void SPI_cursor_move(Portal portal, bool forward, int count);
117117
extern void SPI_cursor_close(Portal portal);
118118

119-
extern void AtEOXact_SPI(void);
119+
extern void AtEOXact_SPI(bool isCommit);
120120

121121
#endif /* SPI_H */

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