diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2013-12-24 17:13:02 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2013-12-24 17:13:02 -0500 |
commit | 1def747db68b234b54b784c74dfbe329f5478b79 (patch) | |
tree | a876dc86ae19f8ca6c94db97204bc141ff4b0a0c /src | |
parent | 4eeda92d86250b702ee6f88fcad2340e5e7d8747 (diff) | |
download | postgresql-1def747db68b234b54b784c74dfbe329f5478b79.tar.gz postgresql-1def747db68b234b54b784c74dfbe329f5478b79.zip |
Fix inadequately-tested code path in tuplesort_skiptuples().
Per report from Jeff Davis.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/utils/sort/tuplesort.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/backend/utils/sort/tuplesort.c b/src/backend/utils/sort/tuplesort.c index 6221f6db7ed..52f05e6d9ad 100644 --- a/src/backend/utils/sort/tuplesort.c +++ b/src/backend/utils/sort/tuplesort.c @@ -1725,6 +1725,8 @@ tuplesort_getdatum(Tuplesortstate *state, bool forward, bool tuplesort_skiptuples(Tuplesortstate *state, int64 ntuples, bool forward) { + MemoryContext oldcontext; + /* * We don't actually support backwards skip yet, because no callers need * 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 * not worth the trouble. */ + oldcontext = MemoryContextSwitchTo(state->sortcontext); while (ntuples-- > 0) { SortTuple stup; @@ -1767,11 +1770,15 @@ tuplesort_skiptuples(Tuplesortstate *state, int64 ntuples, bool forward) if (!tuplesort_gettuple_common(state, forward, &stup, &should_free)) + { + MemoryContextSwitchTo(oldcontext); return false; - if (should_free) + } + if (should_free && stup.tuple) pfree(stup.tuple); CHECK_FOR_INTERRUPTS(); } + MemoryContextSwitchTo(oldcontext); return true; default: |