Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 91964c3

Browse files
committed
Fix unsafe coding in ReorderBufferCommit().
"iterstate" must be marked volatile since it's changed inside the PG_TRY block and then used in the PG_CATCH stanza. Noted by Mark Wilding of Salesforce. (We really need to see if we can't get the C compiler to warn about this.) Also, reset iterstate to NULL after the mainline ReorderBufferIterTXNFinish call, to ensure the PG_CATCH block doesn't try to do that a second time.
1 parent d51d4ff commit 91964c3

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/backend/replication/logical/reorderbuffer.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ ReorderBufferCommit(ReorderBuffer *rb, TransactionId xid,
12591259
TimestampTz commit_time)
12601260
{
12611261
ReorderBufferTXN *txn;
1262-
ReorderBufferIterTXNState *iterstate = NULL;
1262+
ReorderBufferIterTXNState *volatile iterstate = NULL;
12631263
ReorderBufferChange *change;
12641264

12651265
volatile CommandId command_id = FirstCommandId;
@@ -1304,7 +1304,6 @@ ReorderBufferCommit(ReorderBuffer *rb, TransactionId xid,
13041304

13051305
PG_TRY();
13061306
{
1307-
13081307
/*
13091308
* Decoding needs access to syscaches et al., which in turn use
13101309
* heavyweight locks and such. Thus we need to have enough state
@@ -1473,7 +1472,9 @@ ReorderBufferCommit(ReorderBuffer *rb, TransactionId xid,
14731472
}
14741473
}
14751474

1475+
/* clean up the iterator */
14761476
ReorderBufferIterTXNFinish(rb, iterstate);
1477+
iterstate = NULL;
14771478

14781479
/* call commit callback */
14791480
rb->commit(rb, txn, commit_lsn);
@@ -1640,7 +1641,7 @@ ReorderBufferForget(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn)
16401641
*/
16411642
if (txn->base_snapshot != NULL && txn->ninvalidations > 0)
16421643
{
1643-
bool use_subtxn = IsTransactionOrTransactionBlock();
1644+
bool use_subtxn = IsTransactionOrTransactionBlock();
16441645

16451646
if (use_subtxn)
16461647
BeginInternalSubTransaction("replay");

0 commit comments

Comments
 (0)