Skip to content

Commit f8a4dd2

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 586dd5d commit f8a4dd2

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
@@ -1258,7 +1258,7 @@ ReorderBufferCommit(ReorderBuffer *rb, TransactionId xid,
12581258
TimestampTz commit_time)
12591259
{
12601260
ReorderBufferTXN *txn;
1261-
ReorderBufferIterTXNState *iterstate = NULL;
1261+
ReorderBufferIterTXNState *volatile iterstate = NULL;
12621262
ReorderBufferChange *change;
12631263

12641264
volatile CommandId command_id = FirstCommandId;
@@ -1303,7 +1303,6 @@ ReorderBufferCommit(ReorderBuffer *rb, TransactionId xid,
13031303

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

1474+
/* clean up the iterator */
14751475
ReorderBufferIterTXNFinish(rb, iterstate);
1476+
iterstate = NULL;
14761477

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

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

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