Skip to content

Commit b8a78af

Browse files
HuSen8891my-ship-it
authored andcommitted
Fix: quick exit in dumptuples if query execution is finished
If QueryFinishPending is set when query is running into dumptuples, the tuplecontext is reset but memtuples are not cumsumed. When query is running into dumptuples again, tuplesort_sort_memtuples will access these memtuples, and the memory allocated in tuplecontext is already freed, this will cause invalid memory access. To avoid this situation, do nothing in dumptuples if QueryFinishPending is set.
1 parent 4a2dd03 commit b8a78af

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/backend/utils/sort/tuplesort.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3232,6 +3232,14 @@ dumptuples(Tuplesortstate *state, bool alltuples)
32323232
!alltuples)
32333233
return;
32343234

3235+
/*
3236+
* do nothing if we are told to finish execution.
3237+
*/
3238+
if (QueryFinishPending)
3239+
{
3240+
return;
3241+
}
3242+
32353243
/*
32363244
* Final call might require no sorting, in rare cases where we just so
32373245
* happen to have previously LACKMEM()'d at the point where exactly all

0 commit comments

Comments
 (0)