Fix use-after-release mistake in currtid() and currtid2() for views
authorMichael Paquier <[email protected]>
Mon, 1 Jun 2020 05:41:46 +0000 (14:41 +0900)
committerMichael Paquier <[email protected]>
Mon, 1 Jun 2020 05:41:46 +0000 (14:41 +0900)
This issue has been present since the introduction of this code as of
a3519a2 from 2002, and has been found by buildfarm member prion that
uses RELCACHE_FORCE_RELEASE via the tests introduced recently in
e786be5.

Discussion: https://postgr.es/m/20200601022055[email protected]
Backpatch-through: 9.5

src/backend/utils/adt/tid.c

index 5157899c23613ccf129f2fb59a6a99183c0b99ed..c4be647f049a306ccd52021944c0ecf3a4e5d36c 100644 (file)
@@ -313,8 +313,13 @@ currtid_for_view(Relation viewrel, ItemPointer tid)
                    rte = rt_fetch(var->varno, query->rtable);
                    if (rte)
                    {
+                       Datum       result;
+
+                       result = DirectFunctionCall2(currtid_byreloid,
+                                                    ObjectIdGetDatum(rte->relid),
+                                                    PointerGetDatum(tid));
                        heap_close(viewrel, AccessShareLock);
-                       return DirectFunctionCall2(currtid_byreloid, ObjectIdGetDatum(rte->relid), PointerGetDatum(tid));
+                       return result;
                    }
                }
            }