diff options
author | Robert Haas <rhaas@postgresql.org> | 2017-03-31 21:15:05 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2017-03-31 21:15:05 -0400 |
commit | 25dc142a49c60c3107480c487cd8444dc83f9bdf (patch) | |
tree | 2b6297882639eb9f0e66eb229b3213ae1125d52c /src/backend/executor/nodeGatherMerge.c | |
parent | 7d8f6986b83c9a56f6ea11c959cdd8f52e1b543d (diff) | |
download | postgresql-25dc142a49c60c3107480c487cd8444dc83f9bdf.tar.gz postgresql-25dc142a49c60c3107480c487cd8444dc83f9bdf.zip |
Avoid GatherMerge crash when there are no workers.
It's unnecessary to return an actual slot when we have no tuple.
We can just return NULL, which avoids the risk of indexing into an
array that might not contain any elements.
Rushabh Lathia, per a report from Tomas Vondra
Discussion: http://postgr.es/m/6ecd6f17-0dcf-1de7-ded8-0de7db1ddc88@2ndquadrant.com
Diffstat (limited to 'src/backend/executor/nodeGatherMerge.c')
-rw-r--r-- | src/backend/executor/nodeGatherMerge.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/src/backend/executor/nodeGatherMerge.c b/src/backend/executor/nodeGatherMerge.c index 3f0c3ee4d18..62c399e0b18 100644 --- a/src/backend/executor/nodeGatherMerge.c +++ b/src/backend/executor/nodeGatherMerge.c @@ -419,10 +419,9 @@ reread: } /* - * Clear out the tuple table slots for each gather merge input, - * and return a cleared slot. + * Clear out the tuple table slots for each gather merge input. */ -static TupleTableSlot * +static void gather_merge_clear_slots(GatherMergeState *gm_state) { int i; @@ -437,9 +436,6 @@ gather_merge_clear_slots(GatherMergeState *gm_state) pfree(gm_state->gm_tuple_buffers); /* Free the binaryheap, which was created for sort */ binaryheap_free(gm_state->gm_heap); - - /* return any clear slot */ - return gm_state->gm_slots[0]; } /* @@ -479,7 +475,8 @@ gather_merge_getnext(GatherMergeState *gm_state) if (binaryheap_empty(gm_state->gm_heap)) { /* All the queues are exhausted, and so is the heap */ - return gather_merge_clear_slots(gm_state); + gather_merge_clear_slots(gm_state); + return NULL; } else { |