mirror of
https://github.com/postgres/postgres.git
synced 2025-05-11 05:41:32 +03:00
Fix inadequately-tested code path in tuplesort_skiptuples().
Per report from Jeff Davis.
This commit is contained in:
parent
4eeda92d86
commit
1def747db6
@ -1725,6 +1725,8 @@ tuplesort_getdatum(Tuplesortstate *state, bool forward,
|
|||||||
bool
|
bool
|
||||||
tuplesort_skiptuples(Tuplesortstate *state, int64 ntuples, bool forward)
|
tuplesort_skiptuples(Tuplesortstate *state, int64 ntuples, bool forward)
|
||||||
{
|
{
|
||||||
|
MemoryContext oldcontext;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We don't actually support backwards skip yet, because no callers need
|
* We don't actually support backwards skip yet, because no callers need
|
||||||
* it. The API is designed to allow for that later, though.
|
* it. The API is designed to allow for that later, though.
|
||||||
@ -1760,6 +1762,7 @@ tuplesort_skiptuples(Tuplesortstate *state, int64 ntuples, bool forward)
|
|||||||
* We could probably optimize these cases better, but for now it's
|
* We could probably optimize these cases better, but for now it's
|
||||||
* not worth the trouble.
|
* not worth the trouble.
|
||||||
*/
|
*/
|
||||||
|
oldcontext = MemoryContextSwitchTo(state->sortcontext);
|
||||||
while (ntuples-- > 0)
|
while (ntuples-- > 0)
|
||||||
{
|
{
|
||||||
SortTuple stup;
|
SortTuple stup;
|
||||||
@ -1767,11 +1770,15 @@ tuplesort_skiptuples(Tuplesortstate *state, int64 ntuples, bool forward)
|
|||||||
|
|
||||||
if (!tuplesort_gettuple_common(state, forward,
|
if (!tuplesort_gettuple_common(state, forward,
|
||||||
&stup, &should_free))
|
&stup, &should_free))
|
||||||
|
{
|
||||||
|
MemoryContextSwitchTo(oldcontext);
|
||||||
return false;
|
return false;
|
||||||
if (should_free)
|
}
|
||||||
|
if (should_free && stup.tuple)
|
||||||
pfree(stup.tuple);
|
pfree(stup.tuple);
|
||||||
CHECK_FOR_INTERRUPTS();
|
CHECK_FOR_INTERRUPTS();
|
||||||
}
|
}
|
||||||
|
MemoryContextSwitchTo(oldcontext);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user