smgr: Make SMgrRelation initialization safer against errors
authorAndres Freund <andres@anarazel.de>
Tue, 18 Mar 2025 17:43:10 +0000 (13:43 -0400)
committerAndres Freund <andres@anarazel.de>
Tue, 18 Mar 2025 17:44:10 +0000 (13:44 -0400)
In case the smgr_open callback failed, the ->pincount field would not be
initialized and the relation would not be put onto the unpinned_relns list.

This buglet was introduced in 21d9c3ee4ef7, in 17.

Discussion: https://postgr.es/m/3vae7l5ozvqtxmd7rr7zaeq3qkuipz365u3rtim5t5wdkr6f4g@vkgf2fogjirl
Backpatch-through: 17

src/backend/storage/smgr/smgr.c

index 465e3356c538be4d13bbbc4c2af2399806b3215a..bfdaac4721d285925bf171808289d79a938981c0 100644 (file)
@@ -231,12 +231,12 @@ smgropen(RelFileLocator rlocator, ProcNumber backend)
            reln->smgr_cached_nblocks[i] = InvalidBlockNumber;
        reln->smgr_which = 0;   /* we only have md.c at present */
 
-       /* implementation-specific initialization */
-       smgrsw[reln->smgr_which].smgr_open(reln);
-
        /* it is not pinned yet */
        reln->pincount = 0;
        dlist_push_tail(&unpinned_relns, &reln->node);
+
+       /* implementation-specific initialization */
+       smgrsw[reln->smgr_which].smgr_open(reln);
    }
 
    return reln;