1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-27 23:21:58 +03:00

Don't use static storage for SaveTransactionCharacteristics().

This is pretty queasy-making on general principles, and the more so
once you notice that CommitTransactionCommand() is actually stomping
on the values saved by _SPI_commit().  It's okay as long as the
active values didn't change during HoldPinnedPortals(); but that's
a larger assumption than I think we want to make, especially since
the fix is so simple.

Discussion: https://postgr.es/m/1533956.1645731245@sss.pgh.pa.us
This commit is contained in:
Tom Lane
2022-02-28 12:54:12 -05:00
parent 2e517818f4
commit 12d768e704
3 changed files with 32 additions and 28 deletions

View File

@ -228,6 +228,7 @@ static void
_SPI_commit(bool chain)
{
MemoryContext oldcontext = CurrentMemoryContext;
SavedTransactionCharacteristics savetc;
/*
* Complain if we are in a context that doesn't permit transaction
@ -255,9 +256,8 @@ _SPI_commit(bool chain)
(errcode(ERRCODE_INVALID_TRANSACTION_TERMINATION),
errmsg("cannot commit while a subtransaction is active")));
/* XXX this ain't re-entrant enough for my taste */
if (chain)
SaveTransactionCharacteristics();
SaveTransactionCharacteristics(&savetc);
/* Catch any error occurring during the COMMIT */
PG_TRY();
@ -281,7 +281,7 @@ _SPI_commit(bool chain)
/* Immediately start a new transaction */
StartTransactionCommand();
if (chain)
RestoreTransactionCharacteristics();
RestoreTransactionCharacteristics(&savetc);
MemoryContextSwitchTo(oldcontext);
@ -305,7 +305,7 @@ _SPI_commit(bool chain)
/* ... and start a new one */
StartTransactionCommand();
if (chain)
RestoreTransactionCharacteristics();
RestoreTransactionCharacteristics(&savetc);
MemoryContextSwitchTo(oldcontext);
@ -333,6 +333,7 @@ static void
_SPI_rollback(bool chain)
{
MemoryContext oldcontext = CurrentMemoryContext;
SavedTransactionCharacteristics savetc;
/* see under SPI_commit() */
if (_SPI_current->atomic)
@ -346,9 +347,8 @@ _SPI_rollback(bool chain)
(errcode(ERRCODE_INVALID_TRANSACTION_TERMINATION),
errmsg("cannot roll back while a subtransaction is active")));
/* XXX this ain't re-entrant enough for my taste */
if (chain)
SaveTransactionCharacteristics();
SaveTransactionCharacteristics(&savetc);
/* Catch any error occurring during the ROLLBACK */
PG_TRY();
@ -373,7 +373,7 @@ _SPI_rollback(bool chain)
/* Immediately start a new transaction */
StartTransactionCommand();
if (chain)
RestoreTransactionCharacteristics();
RestoreTransactionCharacteristics(&savetc);
MemoryContextSwitchTo(oldcontext);
@ -398,7 +398,7 @@ _SPI_rollback(bool chain)
/* ... and start a new one */
StartTransactionCommand();
if (chain)
RestoreTransactionCharacteristics();
RestoreTransactionCharacteristics(&savetc);
MemoryContextSwitchTo(oldcontext);