aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam/xact.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2004-10-04 21:52:15 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2004-10-04 21:52:15 +0000
commit4c77cbb272948e96ce3ed02d444a944eb45d45e3 (patch)
treef3dfa5472465d452fad976c83cc15b1038249fe8 /src/backend/access/transam/xact.c
parentee7de3d66296513d50b6df1166f6fc84e2b9b5fe (diff)
downloadpostgresql-4c77cbb272948e96ce3ed02d444a944eb45d45e3.tar.gz
postgresql-4c77cbb272948e96ce3ed02d444a944eb45d45e3.zip
PortalRun must guard against the possibility that the portal it's
running contains VACUUM or a similar command that will internally start and commit transactions. In such a case, the original caller values of CurrentMemoryContext and CurrentResourceOwner will point to objects that will be destroyed by the internal commit. We must restore these pointers to point to the newly-manufactured transaction context and resource owner, rather than possibly pointing to deleted memory. Also tweak xact.c so that AbortTransaction and AbortSubTransaction forcibly restore a sane value for CurrentResourceOwner, much as they have always done for CurrentMemoryContext. I'm not certain this is necessary but I'm feeling paranoid today. Responds to Sean Chittenden's bug report of 4-Oct.
Diffstat (limited to 'src/backend/access/transam/xact.c')
-rw-r--r--src/backend/access/transam/xact.c36
1 files changed, 33 insertions, 3 deletions
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index 17db7dd78d5..321a86f30c2 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.190 2004/09/16 20:17:16 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.191 2004/10/04 21:52:14 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -205,6 +205,7 @@ static void AssignSubTransactionId(TransactionState s);
static void AbortTransaction(void);
static void AtAbort_Memory(void);
static void AtCleanup_Memory(void);
+static void AtAbort_ResourceOwner(void);
static void AtCommit_LocalCache(void);
static void AtCommit_Memory(void);
static void AtStart_Cache(void);
@@ -229,6 +230,7 @@ static void PopTransaction(void);
static void AtSubAbort_Memory(void);
static void AtSubCleanup_Memory(void);
+static void AtSubAbort_ResourceOwner(void);
static void AtSubCommit_Memory(void);
static void AtSubStart_Memory(void);
static void AtSubStart_ResourceOwner(void);
@@ -1103,7 +1105,6 @@ AtAbort_Memory(void)
MemoryContextSwitchTo(TopMemoryContext);
}
-
/*
* AtSubAbort_Memory
*/
@@ -1115,6 +1116,33 @@ AtSubAbort_Memory(void)
MemoryContextSwitchTo(TopTransactionContext);
}
+
+/*
+ * AtAbort_ResourceOwner
+ */
+static void
+AtAbort_ResourceOwner(void)
+{
+ /*
+ * Make sure we have a valid ResourceOwner, if possible (else it
+ * will be NULL, which is OK)
+ */
+ CurrentResourceOwner = TopTransactionResourceOwner;
+}
+
+/*
+ * AtSubAbort_ResourceOwner
+ */
+static void
+AtSubAbort_ResourceOwner(void)
+{
+ TransactionState s = CurrentTransactionState;
+
+ /* Make sure we have a valid ResourceOwner */
+ CurrentResourceOwner = s->curTransactionOwner;
+}
+
+
/*
* AtSubAbort_childXids
*/
@@ -1598,8 +1626,9 @@ AbortTransaction(void)
*/
s->state = TRANS_ABORT;
- /* Make sure we are in a valid memory context */
+ /* Make sure we have a valid memory context and resource owner */
AtAbort_Memory();
+ AtAbort_ResourceOwner();
/*
* Reset user id which might have been changed transiently. We cannot
@@ -3338,6 +3367,7 @@ AbortSubTransaction(void)
* do abort processing
*/
AtSubAbort_Memory();
+ AtSubAbort_ResourceOwner();
/*
* We can skip all this stuff if the subxact failed before creating