gin-palloc-fix.patch

text/x-patch

Filename: gin-palloc-fix.patch
Type: text/x-patch
Part: 0
Message: Re: PG18 GIN parallel index build crash - invalid memory alloc request size

Patch

Format: unified
File+
src/backend/access/gin/gininsert.c 2 2
diff --git a/src/backend/access/gin/gininsert.c b/src/backend/access/gin/gininsert.c
index 3d71b442aa9..3499a49a8f4 100644
--- a/src/backend/access/gin/gininsert.c
+++ b/src/backend/access/gin/gininsert.c
@@ -1496,9 +1496,9 @@ GinBufferStoreTuple(GinBuffer *buffer, GinTuple *tup)
 		 * still pass 0 as number of elements in that array though.
 		 */
 		if (buffer->items == NULL)
-			buffer->items = palloc((buffer->nitems + tup->nitems) * sizeof(ItemPointerData));
+			buffer->items = MemoryContextAllocHuge(CurrentMemoryContext, (buffer->nitems + tup->nitems) * sizeof(ItemPointerData));
 		else
-			buffer->items = repalloc(buffer->items,
+			buffer->items = repalloc_huge(buffer->items,
 									 (buffer->nitems + tup->nitems) * sizeof(ItemPointerData));
 
 		new = ginMergeItemPointers(&buffer->items[buffer->nfrozen], /* first unfrozen */