]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix cache reference leak in contrib/sepgsql.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 16 Apr 2020 18:45:54 +0000 (14:45 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 16 Apr 2020 18:45:54 +0000 (14:45 -0400)
fixup_whole_row_references() did the wrong thing with a dropped column,
resulting in a commit-time warning about a cache reference leak.

I (tgl) added a test case exercising this, but back-patched the test
only as far as v10; the patch didn't apply cleanly to 9.6 and it
didn't seem worth the trouble to adapt it.  The bug is pretty old
though, so apply the code change all the way back.

Michael Luo, with cosmetic improvements by me

Discussion: https://postgr.es/m/BYAPR08MB5606D1453D7F50E2AF4D2FD29AD80@BYAPR08MB5606.namprd08.prod.outlook.com

contrib/sepgsql/dml.c

index 4a71753d3fb55a62bdd300a2e16aa4f3e72ee2f1..c8c542070f0dbff7ba005af633da0f05cc853480 100644 (file)
@@ -31,9 +31,9 @@
 /*
  * fixup_whole_row_references
  *
- * When user reference a whole of row, it is equivalent to reference to
+ * When user references a whole-row Var, it is equivalent to referencing
  * all the user columns (not system columns). So, we need to fix up the
- * given bitmapset, if it contains a whole of the row reference.
+ * given bitmapset, if it contains a whole-row reference.
  */
 static Bitmapset *
 fixup_whole_row_references(Oid relOid, Bitmapset *columns)
@@ -44,7 +44,7 @@ fixup_whole_row_references(Oid relOid, Bitmapset *columns)
        AttrNumber      attno;
        int                     index;
 
-       /* if no whole of row references, do not anything */
+       /* if no whole-row references, nothing to do */
        index = InvalidAttrNumber - FirstLowInvalidHeapAttributeNumber;
        if (!bms_is_member(index, columns))
                return columns;
@@ -56,7 +56,7 @@ fixup_whole_row_references(Oid relOid, Bitmapset *columns)
        natts = ((Form_pg_class) GETSTRUCT(tuple))->relnatts;
        ReleaseSysCache(tuple);
 
-       /* fix up the given columns */
+       /* remove bit 0 from column set, add in all the non-dropped columns */
        result = bms_copy(columns);
        result = bms_del_member(result, index);
 
@@ -66,14 +66,13 @@ fixup_whole_row_references(Oid relOid, Bitmapset *columns)
                                                                ObjectIdGetDatum(relOid),
                                                                Int16GetDatum(attno));
                if (!HeapTupleIsValid(tuple))
-                       continue;
-
-               if (((Form_pg_attribute) GETSTRUCT(tuple))->attisdropped)
-                       continue;
-
-               index = attno - FirstLowInvalidHeapAttributeNumber;
+                       continue;                       /* unexpected case, should we error? */
 
-               result = bms_add_member(result, index);
+               if (!((Form_pg_attribute) GETSTRUCT(tuple))->attisdropped)
+               {
+                       index = attno - FirstLowInvalidHeapAttributeNumber;
+                       result = bms_add_member(result, index);
+               }
 
                ReleaseSysCache(tuple);
        }