Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d810720

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 3d0d3c0 commit d810720

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
@@ -499,27 +499,32 @@ ginVacuumEntryPage(GinVacuumState *gvs, Buffer buffer, BlockNumber *roots, uint3
499499
else if (GinGetNPosting(itup) > 0)
500500
{
501501
int nitems;
502-
ItemPointer uncompressed;
502+
ItemPointer items_orig;
503+
bool free_items_orig;
504+
ItemPointer items;
503505

504-
/*
505-
* Vacuum posting list with proper function for compressed and
506-
* uncompressed format.
507-
*/
506+
/* Get list of item pointers from the tuple. */
508507
if (GinItupIsCompressed(itup))
509-
uncompressed = ginPostingListDecode((GinPostingList *) GinGetPosting(itup), &nitems);
508+
{
509+
items_orig = ginPostingListDecode((GinPostingList *) GinGetPosting(itup), &nitems);
510+
free_items_orig = true;
511+
}
510512
else
511513
{
512-
uncompressed = (ItemPointer) GinGetPosting(itup);
514+
items_orig = (ItemPointer) GinGetPosting(itup);
513515
nitems = GinGetNPosting(itup);
516+
free_items_orig = false;
514517
}
515518

516-
uncompressed = ginVacuumItemPointers(gvs, uncompressed, nitems,
517-
&nitems);
518-
if (uncompressed)
519+
/* Remove any items from the list that need to be vacuumed. */
520+
items = ginVacuumItemPointers(gvs, items_orig, nitems, &nitems);
521+
522+
if (free_items_orig)
523+
pfree(items_orig);
524+
525+
/* If any item pointers were removed, recreate the tuple. */
526+
if (items)
519527
{
520-
/*
521-
* Some ItemPointers were deleted, recreate tuple.
522-
*/
523528
OffsetNumber attnum;
524529
Datum key;
525530
GinNullCategory category;
@@ -528,7 +533,7 @@ ginVacuumEntryPage(GinVacuumState *gvs, Buffer buffer, BlockNumber *roots, uint3
528533

529534
if (nitems > 0)
530535
{
531-
plist = ginCompressPostingList(uncompressed, nitems, GinMaxItemSize, NULL);
536+
plist = ginCompressPostingList(items, nitems, GinMaxItemSize, NULL);
532537
plistsize = SizeOfGinPostingList(plist);
533538
}
534539
else
@@ -567,6 +572,7 @@ ginVacuumEntryPage(GinVacuumState *gvs, Buffer buffer, BlockNumber *roots, uint3
567572
RelationGetRelationName(gvs->index));
568573

569574
pfree(itup);
575+
pfree(items);
570576
}
571577
}
572578
}

0 commit comments

Comments
 (0)