mirror of
https://github.com/postgres/postgres.git
synced 2025-06-16 06:01:02 +03:00
Fix memory leaks in GIN index vacuum.
Per bug #12850 by Walter Nordmann. Backpatch to 9.4 where the leak was introduced.
This commit is contained in:
@ -432,27 +432,32 @@ ginVacuumEntryPage(GinVacuumState *gvs, Buffer buffer, BlockNumber *roots, uint3
|
|||||||
else if (GinGetNPosting(itup) > 0)
|
else if (GinGetNPosting(itup) > 0)
|
||||||
{
|
{
|
||||||
int nitems;
|
int nitems;
|
||||||
ItemPointer uncompressed;
|
ItemPointer items_orig;
|
||||||
|
bool free_items_orig;
|
||||||
|
ItemPointer items;
|
||||||
|
|
||||||
/*
|
/* Get list of item pointers from the tuple. */
|
||||||
* Vacuum posting list with proper function for compressed and
|
|
||||||
* uncompressed format.
|
|
||||||
*/
|
|
||||||
if (GinItupIsCompressed(itup))
|
if (GinItupIsCompressed(itup))
|
||||||
uncompressed = ginPostingListDecode((GinPostingList *) GinGetPosting(itup), &nitems);
|
{
|
||||||
|
items_orig = ginPostingListDecode((GinPostingList *) GinGetPosting(itup), &nitems);
|
||||||
|
free_items_orig = true;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uncompressed = (ItemPointer) GinGetPosting(itup);
|
items_orig = (ItemPointer) GinGetPosting(itup);
|
||||||
nitems = GinGetNPosting(itup);
|
nitems = GinGetNPosting(itup);
|
||||||
|
free_items_orig = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uncompressed = ginVacuumItemPointers(gvs, uncompressed, nitems,
|
/* Remove any items from the list that need to be vacuumed. */
|
||||||
&nitems);
|
items = ginVacuumItemPointers(gvs, items_orig, nitems, &nitems);
|
||||||
if (uncompressed)
|
|
||||||
|
if (free_items_orig)
|
||||||
|
pfree(items_orig);
|
||||||
|
|
||||||
|
/* If any item pointers were removed, recreate the tuple. */
|
||||||
|
if (items)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
* Some ItemPointers were deleted, recreate tuple.
|
|
||||||
*/
|
|
||||||
OffsetNumber attnum;
|
OffsetNumber attnum;
|
||||||
Datum key;
|
Datum key;
|
||||||
GinNullCategory category;
|
GinNullCategory category;
|
||||||
@ -461,7 +466,7 @@ ginVacuumEntryPage(GinVacuumState *gvs, Buffer buffer, BlockNumber *roots, uint3
|
|||||||
|
|
||||||
if (nitems > 0)
|
if (nitems > 0)
|
||||||
{
|
{
|
||||||
plist = ginCompressPostingList(uncompressed, nitems, GinMaxItemSize, NULL);
|
plist = ginCompressPostingList(items, nitems, GinMaxItemSize, NULL);
|
||||||
plistsize = SizeOfGinPostingList(plist);
|
plistsize = SizeOfGinPostingList(plist);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -500,6 +505,7 @@ ginVacuumEntryPage(GinVacuumState *gvs, Buffer buffer, BlockNumber *roots, uint3
|
|||||||
RelationGetRelationName(gvs->index));
|
RelationGetRelationName(gvs->index));
|
||||||
|
|
||||||
pfree(itup);
|
pfree(itup);
|
||||||
|
pfree(items);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user