Avoid using a fake relcache entry to own an SmgrRelation.
authorRobert Haas <rhaas@postgresql.org>
Fri, 12 Aug 2022 12:25:41 +0000 (08:25 -0400)
committerRobert Haas <rhaas@postgresql.org>
Fri, 12 Aug 2022 12:25:41 +0000 (08:25 -0400)
commit76733b399c490885564a560718de23d98bb5e66d
tree45f1fcf1650e4b4b02af7b0d062f10d2232d4eef
parent3d895bc846f25859bd6dd242fbf204e6c5166e6f
Avoid using a fake relcache entry to own an SmgrRelation.

If an error occurs before we close the fake relcache entry, the the
fake relcache entry will be destroyed by the SmgrRelation will
survive until end of transaction. Its smgr_owner pointer ends up
pointing to already-freed memory.

The original reason for using a fake relcache entry here was to try
to avoid reusing an SMgrRelation across a relevant invalidation. To
avoid that problem, just call smgropen() again each time we need a
reference to it. Hopefully someday we will come up with a more
elegant approach, but accessing uninitialized memory is bad so let's
do this for now.

Dilip Kumar, reviewed by Andres Freund and Tom Lane. Report by
Justin Pryzby.

Discussion: http://postgr.es/m/20220802175043.GA13682@telsasoft.com
Discussion: http://postgr.es/m/CAFiTN-vSFeE6_W9z698XNtFROOA_nSqUXWqLcG0emob_kJ+dEQ@mail.gmail.com
src/backend/commands/dbcommands.c
src/backend/storage/buffer/bufmgr.c