mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-04 00:02:52 -05:00 
			
		
		
		
	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
This commit is contained in:
		
							parent
							
								
									0fd336c61d
								
							
						
					
					
						commit
						e2605c8311
					
				@ -8,7 +8,7 @@
 | 
				
			|||||||
 *
 | 
					 *
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * IDENTIFICATION
 | 
					 * IDENTIFICATION
 | 
				
			||||||
 *	  $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.157 2003/11/29 19:51:40 pgsql Exp $
 | 
					 *	  $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.158 2003/12/02 19:26:47 joe Exp $
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * NOTES
 | 
					 * NOTES
 | 
				
			||||||
 *		Transaction aborts can now occur two ways:
 | 
					 *		Transaction aborts can now occur two ways:
 | 
				
			||||||
@ -977,7 +977,7 @@ CommitTransaction(void)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	CallEOXactCallbacks(true);
 | 
						CallEOXactCallbacks(true);
 | 
				
			||||||
	AtEOXact_GUC(true);
 | 
						AtEOXact_GUC(true);
 | 
				
			||||||
	AtEOXact_SPI();
 | 
						AtEOXact_SPI(true);
 | 
				
			||||||
	AtEOXact_gist();
 | 
						AtEOXact_gist();
 | 
				
			||||||
	AtEOXact_hash();
 | 
						AtEOXact_hash();
 | 
				
			||||||
	AtEOXact_nbtree();
 | 
						AtEOXact_nbtree();
 | 
				
			||||||
@ -1087,7 +1087,7 @@ AbortTransaction(void)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	CallEOXactCallbacks(false);
 | 
						CallEOXactCallbacks(false);
 | 
				
			||||||
	AtEOXact_GUC(false);
 | 
						AtEOXact_GUC(false);
 | 
				
			||||||
	AtEOXact_SPI();
 | 
						AtEOXact_SPI(false);
 | 
				
			||||||
	AtEOXact_gist();
 | 
						AtEOXact_gist();
 | 
				
			||||||
	AtEOXact_hash();
 | 
						AtEOXact_hash();
 | 
				
			||||||
	AtEOXact_nbtree();
 | 
						AtEOXact_nbtree();
 | 
				
			||||||
 | 
				
			|||||||
@ -8,7 +8,7 @@
 | 
				
			|||||||
 *
 | 
					 *
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * IDENTIFICATION
 | 
					 * IDENTIFICATION
 | 
				
			||||||
 *	  $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.108 2003/11/29 19:51:48 pgsql Exp $
 | 
					 *	  $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.109 2003/12/02 19:26:47 joe Exp $
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 *-------------------------------------------------------------------------
 | 
					 *-------------------------------------------------------------------------
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@ -174,18 +174,26 @@ SPI_finish(void)
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Clean up SPI state at transaction commit or abort (we don't care which).
 | 
					 * Clean up SPI state at transaction commit or abort.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
AtEOXact_SPI(void)
 | 
					AtEOXact_SPI(bool isCommit)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * Note that memory contexts belonging to SPI stack entries will be
 | 
						 * Note that memory contexts belonging to SPI stack entries will be
 | 
				
			||||||
	 * freed automatically, so we can ignore them here.  We just need to
 | 
						 * freed automatically, so we can ignore them here.  We just need to
 | 
				
			||||||
	 * restore our static variables to initial state.
 | 
						 * restore our static variables to initial state.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	if (_SPI_stack != NULL)		/* there was abort */
 | 
						if (_SPI_stack != NULL)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
		free(_SPI_stack);
 | 
							free(_SPI_stack);
 | 
				
			||||||
 | 
							if (isCommit)
 | 
				
			||||||
 | 
								ereport(WARNING,
 | 
				
			||||||
 | 
										(errcode(ERRCODE_WARNING),
 | 
				
			||||||
 | 
										 errmsg("freeing non-empty SPI stack"),
 | 
				
			||||||
 | 
										 errhint("Check for missing \"SPI_finish\" calls")));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	_SPI_current = _SPI_stack = NULL;
 | 
						_SPI_current = _SPI_stack = NULL;
 | 
				
			||||||
	_SPI_connected = _SPI_curid = -1;
 | 
						_SPI_connected = _SPI_curid = -1;
 | 
				
			||||||
	SPI_processed = 0;
 | 
						SPI_processed = 0;
 | 
				
			||||||
 | 
				
			|||||||
@ -2,7 +2,7 @@
 | 
				
			|||||||
 *
 | 
					 *
 | 
				
			||||||
 * spi.h
 | 
					 * spi.h
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * $PostgreSQL: pgsql/src/include/executor/spi.h,v 1.40 2003/11/29 22:41:01 pgsql Exp $
 | 
					 * $PostgreSQL: pgsql/src/include/executor/spi.h,v 1.41 2003/12/02 19:26:47 joe Exp $
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 *-------------------------------------------------------------------------
 | 
					 *-------------------------------------------------------------------------
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@ -116,6 +116,6 @@ extern void SPI_cursor_fetch(Portal portal, bool forward, int count);
 | 
				
			|||||||
extern void SPI_cursor_move(Portal portal, bool forward, int count);
 | 
					extern void SPI_cursor_move(Portal portal, bool forward, int count);
 | 
				
			||||||
extern void SPI_cursor_close(Portal portal);
 | 
					extern void SPI_cursor_close(Portal portal);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern void AtEOXact_SPI(void);
 | 
					extern void AtEOXact_SPI(bool isCommit);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif   /* SPI_H */
 | 
					#endif   /* SPI_H */
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user