Skip to content

Commit a63521e

Browse files
author
Alexander Korotkov
committed
Prevent leaking tuples from tuplesort.
1 parent 35f40f1 commit a63521e

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

rumget.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,6 +2257,7 @@ insertScanItem(RumScanOpaque so, bool recheck)
22572257
j++;
22582258
}
22592259
rum_tuplesort_putrum(so->sortstate, item);
2260+
pfree(item);
22602261
}
22612262

22622263
bool

rumscan.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,10 @@ freeScanKeys(RumScanOpaque so)
303303
}
304304

305305
pfree(so->entries);
306+
if (so->sortedEntries)
307+
pfree(so->sortedEntries);
306308
so->entries = NULL;
309+
so->sortedEntries = NULL;
307310
so->totalentries = 0;
308311
}
309312

@@ -415,6 +418,7 @@ rumNewScanKey(IndexScanDesc scan)
415418
so->allocentries = 32;
416419
so->entries = (RumScanEntry *)
417420
palloc0(so->allocentries * sizeof(RumScanEntry));
421+
so->sortedEntries = NULL;
418422

419423
so->isVoidRes = false;
420424

rumsort.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1536,12 +1536,15 @@ rum_tuplesort_putrum(Tuplesortstate *state, RumSortItem *item)
15361536
{
15371537
MemoryContext oldcontext = MemoryContextSwitchTo(state->sortcontext);
15381538
SortTuple stup;
1539+
RumSortItem *itemCopy = palloc(RumSortItemSize(state->nKeys));
1540+
1541+
memcpy(itemCopy, item, RumSortItemSize(state->nKeys));
15391542

15401543
/*
15411544
* Copy the given tuple into memory we control, and decrease availMem.
15421545
* Then call the common code.
15431546
*/
1544-
COPYTUP(state, &stup, (void *) item);
1547+
COPYTUP(state, &stup, (void *) itemCopy);
15451548

15461549
puttuple_common(state, &stup);
15471550

0 commit comments

Comments
 (0)