From e10774420cd8f7ab56fdebd6eb49f6e37de46957 Mon Sep 17 00:00:00 2001 From: Amit Kapila Date: Sat, 12 Oct 2019 08:49:34 +0530 Subject: [PATCH] Fix memory allocation for copying the stats. --- src/backend/access/heap/vacuumlazy.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c index 3c5e16608e..ea421e55da 100644 --- a/src/backend/access/heap/vacuumlazy.c +++ b/src/backend/access/heap/vacuumlazy.c @@ -2941,29 +2941,26 @@ begin_parallel_vacuum(LVRelStats *vacrelstats, Oid relid, BlockNumber nblocks, * * All writes are not allowed during parallel mode and it might not be * safe to exit from the parallel mode while keeping the parallel context. - * So we copy the updated index statistics to a temporary space and adjust - * 'stats' so that we can update index statistics after exited from the - * parallel mode. + * So we copy the updated index statistics to a local memory and then later + * use that to update the index statistics. */ static void end_parallel_vacuum(LVParallelState *lps, Relation *Irel, int nindexes, IndexBulkDeleteResult **stats) { - IndexBulkDeleteResult *copied_stats; int i; Assert(!IsParallelWorker()); - /* Copy the updated statistics and adjust each elements of stats */ - copied_stats = palloc(sizeof(IndexBulkDeleteResult) * nindexes); + /* copy the updated statistics */ for (i = 0; i < nindexes; i++) { if (lps->lvshared->indstats[i].updated) { - memcpy(&(copied_stats[i]), + stats[i] = (IndexBulkDeleteResult *) palloc0(sizeof(IndexBulkDeleteResult)); + memcpy(stats[i], &(lps->lvshared->indstats[i].stats), sizeof(IndexBulkDeleteResult)); - stats[i] = &(copied_stats[i]); } else stats[i] = NULL; -- 2.16.2.windows.1