GetRelationPublicationActions. - Remove unreachable code
Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.
You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:
docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t45483psql -h localhost -U postgresBuilt from patchset v3 (message #3), July 27, 2026 at 03:22 PM.
Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:
git clone --branch t45483_3 https://github.com/hackorum-dev/postgres.gitIn a checkout you already have, add the fork once:
git remote add hackorum https://github.com/hackorum-dev/postgres.gitthen, for this patchset and every later one:
git fetch hackorum t45483_3 && git checkout t45483_3Patchset v3 (message #3) is on t45483_3
Hi hackers.
There appears to be some unreachable code in the relcache function
GetRelationPublicationActions.
When the 'relation->rd_pubactions' is not NULL then the function
unconditionally returns early (near the top).
Therefore, the following code (near the bottom) seems to have no
purpose because IIUC the 'rd_pubactions' can never be not NULL here.
if (relation->rd_pubactions)
{
pfree(relation->rd_pubactions);
relation->rd_pubactions = NULL;
}
The latest Code Coverage report [1]https://coverage.postgresql.org/src/backend/utils/cache/relcache.c.gcov.html also shows that this code is never executed.
5601 3556 : if (relation->rd_pubactions)
5602 : {
5603 0 : pfree(relation->rd_pubactions);
5604 0 : relation->rd_pubactions = NULL;
5605 : }
~~
PSA a patch to remove this unreachable code.
------
[1]: https://coverage.postgresql.org/src/backend/utils/cache/relcache.c.gcov.html
Kind Regards,
Peter Smith.
Fujitsu Australia
Attachments:
v1-0001-Remove-unreachable-code-in-GetRelationPublication.patchapplication/octet-stream; name=v1-0001-Remove-unreachable-code-in-GetRelationPublication.patchDownload+0-7
Peter Smith <smithpb2250@gmail.com> writes:
There appears to be some unreachable code in the relcache function
GetRelationPublicationActions.
When the 'relation->rd_pubactions' is not NULL then the function
unconditionally returns early (near the top).
Therefore, the following code (near the bottom) seems to have no
purpose because IIUC the 'rd_pubactions' can never be not NULL here.
I'm not sure it's as unreachable as all that. What you're not
accounting for is the possibility of recursive cache loading,
ie something down inside the catalog fetches we have to do here
could already have made the field valid.
Admittedly, that's probably not very likely given expected usage
patterns (to wit, that system catalogs shouldn't really have
publication actions). But there are other places in relcache.c where
a coding pattern similar to this is demonstrably necessary to avoid
memory leakage. I'd rather leave the code as-is, maybe add a comment
along the lines of "rd_pubactions is probably still NULL, but just in
case something already made it valid, avoid leaking memory".
regards, tom lane
On Thu, Feb 10, 2022 at 11:34 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
Peter Smith <smithpb2250@gmail.com> writes:
There appears to be some unreachable code in the relcache function
GetRelationPublicationActions.
When the 'relation->rd_pubactions' is not NULL then the function
unconditionally returns early (near the top).
Therefore, the following code (near the bottom) seems to have no
purpose because IIUC the 'rd_pubactions' can never be not NULL here.I'm not sure it's as unreachable as all that. What you're not
accounting for is the possibility of recursive cache loading,
ie something down inside the catalog fetches we have to do here
could already have made the field valid.Admittedly, that's probably not very likely given expected usage
patterns (to wit, that system catalogs shouldn't really have
publication actions). But there are other places in relcache.c where
a coding pattern similar to this is demonstrably necessary to avoid
memory leakage. I'd rather leave the code as-is, maybe add a comment
along the lines of "rd_pubactions is probably still NULL, but just in
case something already made it valid, avoid leaking memory".
OK. Thanks for your explanation and advice.
PSA another patch to just a comment as suggested.
------
Kind Regards,
Peter Smith.
Fujitsu Australia