Commit 70a6c37d authored by Amit Kapila's avatar Amit Kapila

Fix memory leak introduced in commit 7df159a6.

We memorize all internal and empty leaf pages in the 1st vacuum stage for
gist indexes.  They are used in the 2nd stage, to delete all the empty
pages.  There was a memory context page_set_context for this purpose, but
we never used it.

Reported-by: Amit Kapila
Author: Dilip Kumar
Reviewed-by: Amit Kapila
Backpatch-through: 12, where it got introduced
Discussion: https://postgr.es/m/CAA4eK1LGr+MN0xHZpJ2dfS8QNQ1a_aROKowZB+MPNep8FVtwAA@mail.gmail.com
parent ba19a6b7
......@@ -169,6 +169,7 @@ gistvacuumscan(IndexVacuumInfo *info, GistBulkDeleteResult *stats,
BlockNumber num_pages;
bool needLock;
BlockNumber blkno;
MemoryContext oldctx;
/*
* Reset counts that will be incremented during the scan; needed in case
......@@ -179,8 +180,17 @@ gistvacuumscan(IndexVacuumInfo *info, GistBulkDeleteResult *stats,
stats->stats.pages_deleted = 0;
stats->stats.pages_free = 0;
MemoryContextReset(stats->page_set_context);
/*
* Create the integer sets to remember all the internal and the empty leaf
* pages in page_set_context. Internally, the integer set will remember
* this context so that the subsequent allocations for these integer sets
* will be done from the same context.
*/
oldctx = MemoryContextSwitchTo(stats->page_set_context);
stats->internal_page_set = intset_create();
stats->empty_leaf_set = intset_create();
MemoryContextSwitchTo(oldctx);
/* Set up info to pass down to gistvacuumpage */
vstate.info = info;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment