Allow callback functions to deregister themselves during a call.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 28 Sep 2022 15:23:14 +0000 (11:23 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 28 Sep 2022 15:23:27 +0000 (11:23 -0400)
commit4d2a844242dcfb34e05dd0d880b1a283a514b16b
treede19f6f2c55ebca0a91a7abd17d38f74b839236d
parentd84a7b290f866b3f16cbefb0fca31b69ebace98a
Allow callback functions to deregister themselves during a call.

Fetch the next-item pointer before the call not after, so that
we aren't dereferencing a dangling pointer if the callback
deregistered itself during the call.  The risky coding pattern
appears in CallXactCallbacks, CallSubXactCallbacks, and
ResourceOwnerReleaseInternal.  (There are some other places that
might be at hazard if they offered deregistration functionality,
but they don't.)

I (tgl) considered back-patching this, but desisted because it
wouldn't be very safe for extensions to rely on this working in
pre-v16 branches.

Hao Wu

Discussion: https://postgr.es/m/CAH+9SWXTiERkmhRke+QCcc+jRH8d5fFHTxh8ZK0-Yn4BSpyaAg@mail.gmail.com
src/backend/access/transam/xact.c
src/backend/utils/resowner/resowner.c