Fix some near-bugs related to ResourceOwner function arguments
authorHeikki Linnakangas <[email protected]>
Wed, 10 Dec 2025 09:43:16 +0000 (11:43 +0200)
committerHeikki Linnakangas <[email protected]>
Wed, 10 Dec 2025 09:43:16 +0000 (11:43 +0200)
These functions took a ResourceOwner argument, but only checked if it
was NULL, and then used CurrentResourceOwner for the actual work.
Surely the intention was to use the passed-in resource owner. All
current callers passed CurrentResourceOwner or NULL, so this has no
consequences at the moment, but it's an accident waiting to happen for
future caller and extensions.

Author: Matthias van de Meent <[email protected]>
Discussion: https://www.postgresql.org/message-id/CAEze2Whnfv8VuRZaohE-Af+GxBA1SNfD_rXfm84Jv-958UCcJA@mail.gmail.com
Backpatch-through: 17

src/backend/storage/aio/aio.c
src/backend/utils/cache/catcache.c

index a12b785ade6c297a8f59fb911912c4f178a85314..c4c2d8cc4b1a1b2ecf5d10774628d68419f27f10 100644 (file)
@@ -53,7 +53,7 @@
 
 static inline void pgaio_io_update_state(PgAioHandle *ioh, PgAioHandleState new_state);
 static void pgaio_io_reclaim(PgAioHandle *ioh);
-static void pgaio_io_resowner_register(PgAioHandle *ioh);
+static void pgaio_io_resowner_register(PgAioHandle *ioh, struct ResourceOwnerData *resowner);
 static void pgaio_io_wait_for_free(void);
 static PgAioHandle *pgaio_io_from_wref(PgAioWaitRef *iow, uint64 *ref_generation);
 static const char *pgaio_io_state_get_name(PgAioHandleState s);
@@ -217,7 +217,7 @@ pgaio_io_acquire_nb(struct ResourceOwnerData *resowner, PgAioReturn *ret)
                pgaio_my_backend->handed_out_io = ioh;
 
                if (resowner)
-                       pgaio_io_resowner_register(ioh);
+                       pgaio_io_resowner_register(ioh, resowner);
 
                if (ret)
                {
@@ -406,13 +406,13 @@ pgaio_io_update_state(PgAioHandle *ioh, PgAioHandleState new_state)
 }
 
 static void
-pgaio_io_resowner_register(PgAioHandle *ioh)
+pgaio_io_resowner_register(PgAioHandle *ioh, struct ResourceOwnerData *resowner)
 {
        Assert(!ioh->resowner);
-       Assert(CurrentResourceOwner);
+       Assert(resowner);
 
-       ResourceOwnerRememberAioHandle(CurrentResourceOwner, &ioh->resowner_node);
-       ioh->resowner = CurrentResourceOwner;
+       ResourceOwnerRememberAioHandle(resowner, &ioh->resowner_node);
+       ioh->resowner = resowner;
 }
 
 /*
index 84f1f80607eed2ee3148a99749a2b0f5b01f37cc..1d09c66ac959255fc5ee3ce3611d98b797dd1b2e 100644 (file)
@@ -1668,7 +1668,7 @@ ReleaseCatCacheWithOwner(HeapTuple tuple, ResourceOwner resowner)
 
        ct->refcount--;
        if (resowner)
-               ResourceOwnerForgetCatCacheRef(CurrentResourceOwner, &ct->tuple);
+               ResourceOwnerForgetCatCacheRef(resowner, &ct->tuple);
 
        if (
 #ifndef CATCACHE_FORCE_RELEASE
@@ -2110,7 +2110,7 @@ ReleaseCatCacheListWithOwner(CatCList *list, ResourceOwner resowner)
        Assert(list->refcount > 0);
        list->refcount--;
        if (resowner)
-               ResourceOwnerForgetCatCacheListRef(CurrentResourceOwner, list);
+               ResourceOwnerForgetCatCacheListRef(resowner, list);
 
        if (
 #ifndef CATCACHE_FORCE_RELEASE