Skip to content

Commit 26d2c5d

Browse files
committed
Fix memory leaks in GIN index vacuum.
Per bug #12850 by Walter Nordmann. Backpatch to 9.4 where the leak was introduced.
1 parent f4abd02 commit 26d2c5d

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

src/backend/access/gin/ginvacuum.c

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -432,27 +432,32 @@ ginVacuumEntryPage(GinVacuumState *gvs, Buffer buffer, BlockNumber *roots, uint3
432432
else if (GinGetNPosting(itup) > 0)
433433
{
434434
int nitems;
435-
ItemPointer uncompressed;
435+
ItemPointer items_orig;
436+
bool free_items_orig;
437+
ItemPointer items;
436438

437-
/*
438-
* Vacuum posting list with proper function for compressed and
439-
* uncompressed format.
440-
*/
439+
/* Get list of item pointers from the tuple. */
441440
if (GinItupIsCompressed(itup))
442-
uncompressed = ginPostingListDecode((GinPostingList *) GinGetPosting(itup), &nitems);
441+
{
442+
items_orig = ginPostingListDecode((GinPostingList *) GinGetPosting(itup), &nitems);
443+
free_items_orig = true;
444+
}
443445
else
444446
{
445-
uncompressed = (ItemPointer) GinGetPosting(itup);
447+
items_orig = (ItemPointer) GinGetPosting(itup);
446448
nitems = GinGetNPosting(itup);
449+
free_items_orig = false;
447450
}
448451

449-
uncompressed = ginVacuumItemPointers(gvs, uncompressed, nitems,
450-
&nitems);
451-
if (uncompressed)
452+
/* Remove any items from the list that need to be vacuumed. */
453+
items = ginVacuumItemPointers(gvs, items_orig, nitems, &nitems);
454+
455+
if (free_items_orig)
456+
pfree(items_orig);
457+
458+
/* If any item pointers were removed, recreate the tuple. */
459+
if (items)
452460
{
453-
/*
454-
* Some ItemPointers were deleted, recreate tuple.
455-
*/
456461
OffsetNumber attnum;
457462
Datum key;
458463
GinNullCategory category;
@@ -461,7 +466,7 @@ ginVacuumEntryPage(GinVacuumState *gvs, Buffer buffer, BlockNumber *roots, uint3
461466

462467
if (nitems > 0)
463468
{
464-
plist = ginCompressPostingList(uncompressed, nitems, GinMaxItemSize, NULL);
469+
plist = ginCompressPostingList(items, nitems, GinMaxItemSize, NULL);
465470
plistsize = SizeOfGinPostingList(plist);
466471
}
467472
else
@@ -500,6 +505,7 @@ ginVacuumEntryPage(GinVacuumState *gvs, Buffer buffer, BlockNumber *roots, uint3
500505
RelationGetRelationName(gvs->index));
501506

502507
pfree(itup);
508+
pfree(items);
503509
}
504510
}
505511
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy