Skip to content

Commit 2403e54

Browse files
committed
Fix RelationIdGetRelation calls that weren't bothering with error checks.
Some of these are quite old, but that doesn't make them not bugs. We'd rather report a failure via elog than SIGSEGV. While at it, uniformly spell the error check as !RelationIsValid(rel) rather than a bare rel == NULL test. The machine code is the same but it seems better to be consistent. Coverity complained about this today, not sure why, because the mistake is in fact old.
1 parent e6af7b3 commit 2403e54

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/backend/replication/logical/reorderbuffer.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -1553,7 +1553,7 @@ ReorderBufferCommit(ReorderBuffer *rb, TransactionId xid,
15531553

15541554
relation = RelationIdGetRelation(reloid);
15551555

1556-
if (relation == NULL)
1556+
if (!RelationIsValid(relation))
15571557
elog(ERROR, "could not open relation with OID %u (for filenode \"%s\")",
15581558
reloid,
15591559
relpathperm(change->data.tp.relnode,
@@ -1671,7 +1671,7 @@ ReorderBufferCommit(ReorderBuffer *rb, TransactionId xid,
16711671

16721672
relation = RelationIdGetRelation(relid);
16731673

1674-
if (relation == NULL)
1674+
if (!RelationIsValid(relation))
16751675
elog(ERROR, "could not open relation with OID %u", relid);
16761676

16771677
if (!RelationIsLogicallyLogged(relation))
@@ -3031,6 +3031,10 @@ ReorderBufferToastReplace(ReorderBuffer *rb, ReorderBufferTXN *txn,
30313031
desc = RelationGetDescr(relation);
30323032

30333033
toast_rel = RelationIdGetRelation(relation->rd_rel->reltoastrelid);
3034+
if (!RelationIsValid(toast_rel))
3035+
elog(ERROR, "could not open relation with OID %u",
3036+
relation->rd_rel->reltoastrelid);
3037+
30343038
toast_desc = RelationGetDescr(toast_rel);
30353039

30363040
/* should we allocate from stack instead? */

0 commit comments

Comments
 (0)