Skip to content

Commit 1def747

Browse files
committed
Fix inadequately-tested code path in tuplesort_skiptuples().
Per report from Jeff Davis.
1 parent 4eeda92 commit 1def747

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/backend/utils/sort/tuplesort.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1725,6 +1725,8 @@ tuplesort_getdatum(Tuplesortstate *state, bool forward,
17251725
bool
17261726
tuplesort_skiptuples(Tuplesortstate *state, int64 ntuples, bool forward)
17271727
{
1728+
MemoryContext oldcontext;
1729+
17281730
/*
17291731
* We don't actually support backwards skip yet, because no callers need
17301732
* it. The API is designed to allow for that later, though.
@@ -1760,18 +1762,23 @@ tuplesort_skiptuples(Tuplesortstate *state, int64 ntuples, bool forward)
17601762
* We could probably optimize these cases better, but for now it's
17611763
* not worth the trouble.
17621764
*/
1765+
oldcontext = MemoryContextSwitchTo(state->sortcontext);
17631766
while (ntuples-- > 0)
17641767
{
17651768
SortTuple stup;
17661769
bool should_free;
17671770

17681771
if (!tuplesort_gettuple_common(state, forward,
17691772
&stup, &should_free))
1773+
{
1774+
MemoryContextSwitchTo(oldcontext);
17701775
return false;
1771-
if (should_free)
1776+
}
1777+
if (should_free && stup.tuple)
17721778
pfree(stup.tuple);
17731779
CHECK_FOR_INTERRUPTS();
17741780
}
1781+
MemoryContextSwitchTo(oldcontext);
17751782
return true;
17761783

17771784
default:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy