Free pre-modification HeapTuple in ALTER TABLE ... TYPE ...
authorAndrew Dunstan <andrew@dunslane.net>
Fri, 11 Jan 2019 22:12:54 +0000 (17:12 -0500)
committerAndrew Dunstan <andrew@dunslane.net>
Fri, 11 Jan 2019 22:16:43 +0000 (17:16 -0500)
This was an oversight in commit 3b174b1a3.

Per offline gripe from Alvaro Herrera

Backpatch to release 11.

src/backend/commands/tablecmds.c

index 463894faeaa75fd01e30a1749051b715b9f4a7b9..71b2e3f1340d0611b3a29911372a535306326a6b 100644 (file)
@@ -9747,6 +9747,7 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,
            Datum       valuesAtt[Natts_pg_attribute];
            bool        nullsAtt[Natts_pg_attribute];
            bool        replacesAtt[Natts_pg_attribute];
+           HeapTuple   newTup;
 
            MemSet(valuesAtt, 0, sizeof(valuesAtt));
            MemSet(nullsAtt, false, sizeof(nullsAtt));
@@ -9772,8 +9773,10 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,
            replacesAtt[Anum_pg_attribute_attmissingval - 1] = true;
            nullsAtt[Anum_pg_attribute_attmissingval - 1] = false;
 
-           heapTup = heap_modify_tuple(heapTup, RelationGetDescr(attrelation),
-                                       valuesAtt, nullsAtt, replacesAtt);
+           newTup = heap_modify_tuple(heapTup, RelationGetDescr(attrelation),
+                                      valuesAtt, nullsAtt, replacesAtt);
+           heap_freetuple(heapTup);
+           heapTup = newTup;
            attTup = (Form_pg_attribute) GETSTRUCT(heapTup);
        }
    }