diff options
author | Amit Kapila <akapila@postgresql.org> | 2019-10-17 08:45:43 +0530 |
---|---|---|
committer | Amit Kapila <akapila@postgresql.org> | 2019-10-21 08:57:32 +0530 |
commit | 70a6c37d524cc2c29712424785be3d9e2e62f484 (patch) | |
tree | 51648d7845a0906802c9d64d652e67b549b6758b /src/backend/access/gist/gistvacuum.c | |
parent | ba19a6b73c5bd771d8864171ede03503a9ff564e (diff) | |
download | postgresql-70a6c37d524cc2c29712424785be3d9e2e62f484.tar.gz postgresql-70a6c37d524cc2c29712424785be3d9e2e62f484.zip |
Fix memory leak introduced in commit 7df159a620.
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
Diffstat (limited to 'src/backend/access/gist/gistvacuum.c')
-rw-r--r-- | src/backend/access/gist/gistvacuum.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/backend/access/gist/gistvacuum.c b/src/backend/access/gist/gistvacuum.c index bf754ea6d0d..710e4015b3d 100644 --- a/src/backend/access/gist/gistvacuum.c +++ b/src/backend/access/gist/gistvacuum.c @@ -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; |