Fix use-after-free introduced in 55ed3defc966
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Thu, 27 Jun 2019 15:57:10 +0000 (11:57 -0400)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Thu, 27 Jun 2019 15:57:10 +0000 (11:57 -0400)
Evidenced by failure under RELCACHE_FORCE_RELEASE (buildfarm member
prion).

Author: Amit Langote
Discussion: https://postgr.es/m/CA+HiwqGV=k_Eh4jBiQw66ivvdG+EUkrEYeHTYL1SvDj_YOYV0g@mail.gmail.com

src/backend/commands/indexcmds.c

index cdbb56f1a4abf39436c942b7119e1da2cc2ff04a..579b99895488aa85128b87ffe2cc59a098db211d 100644 (file)
@@ -1059,13 +1059,11 @@ DefineIndex(Oid relationId,
 
            memcpy(part_oids, partdesc->oids, sizeof(Oid) * nparts);
 
-           parentDesc = CreateTupleDescCopy(RelationGetDescr(rel));
+           parentDesc = RelationGetDescr(rel);
            opfamOids = palloc(sizeof(Oid) * numberOfKeyAttributes);
            for (i = 0; i < numberOfKeyAttributes; i++)
                opfamOids[i] = get_opclass_family(classObjectId[i]);
 
-           table_close(rel, NoLock);
-
            /*
             * For each partition, scan all existing indexes; if one matches
             * our index definition and is not already attached to some other
@@ -1265,13 +1263,12 @@ DefineIndex(Oid relationId,
                heap_freetuple(newtup);
            }
        }
-       else
-           table_close(rel, NoLock);
 
        /*
         * Indexes on partitioned tables are not themselves built, so we're
         * done here.
         */
+       table_close(rel, NoLock);
        if (!OidIsValid(parentIndexId))
            pgstat_progress_end_command();
        return address;