I add MemoryContext listCxt to avoid memory leak. listCxt is created once in gistrescan (only for index-only scan plan ) and reseted when scan of the leaf page is finished.
I do not sure if the problem was completely solved, so I wait for feedback.
* What's the reason for turning GISTScanOpaqueData.pageData from an array to a List?
This array is field of structure GISTScanOpaqueData. Memory for that structure allocated in function gistbeginscan(). The array is static so it's declared only one time in structure:
GISTSearchHeapItem pageData [BLCKSZ/sizeof(IndexTupleData)]
But how could we know size of array if we don't know what data would be returned? I mean type and amount.
I asked Alexander about that and he offered me to use List instead of Array.