Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaa9c4e7

Browse files
committed
Fix memory leak in repeated GIN index searches.
Commitd88976c removed this code from ginFreeScanKeys():-if (entry->list)-pfree(entry->list);evidently in the belief that that ItemPointer array is allocated in thekeyCtx and so would be reclaimed by the following MemoryContextReset.Unfortunately, it isn't and it won't. It'd likely be a good idea forthat to become so, but as a simple and back-patchable fix in themeantime, restore this code to ginFreeScanKeys().Also, add a similar pfree to where startScanEntry() is about to zero outentry->list. I am not sure if there are any code paths where thischange prevents a leak today, but it seems like cheap future-proofing.In passing, make the initial allocation of so->entries[] use pallocnot palloc0. The code doesn't depend on unused entries being zero;if it did, the array-enlargement code in ginFillScanEntry() would bewrong. So using palloc0 initially can only serve to confuse readersabout what the invariant is.Per report from Felipe de Jesús Molina Bravo, via Jaime Casanova in<CAJGNTeMR1ndMU2Thpr8GPDUfiHTV7idELJRFusA5UXUGY1y-eA@mail.gmail.com>
1 parenta7915f1 commitaa9c4e7

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

‎src/backend/access/gin/ginget.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ startScanEntry(GinState *ginstate, GinScanEntry entry)
302302
entry->buffer=InvalidBuffer;
303303
ItemPointerSetMin(&entry->curItem);
304304
entry->offset=InvalidOffsetNumber;
305+
if (entry->list)
306+
pfree(entry->list);
305307
entry->list=NULL;
306308
entry->nlist=0;
307309
entry->matchBitmap=NULL;

‎src/backend/access/gin/ginscan.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ ginFreeScanKeys(GinScanOpaque so)
249249

250250
if (entry->buffer!=InvalidBuffer)
251251
ReleaseBuffer(entry->buffer);
252+
if (entry->list)
253+
pfree(entry->list);
252254
if (entry->matchIterator)
253255
tbm_end_iterate(entry->matchIterator);
254256
if (entry->matchBitmap)
@@ -288,7 +290,7 @@ ginNewScanKey(IndexScanDesc scan)
288290
so->totalentries=0;
289291
so->allocentries=32;
290292
so->entries= (GinScanEntry*)
291-
palloc0(so->allocentries*sizeof(GinScanEntry));
293+
palloc(so->allocentries*sizeof(GinScanEntry));
292294

293295
so->isVoidRes= false;
294296

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp