aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2016-12-05 15:54:28 -0500
committerRobert Haas <rhaas@postgresql.org>2016-12-05 15:59:02 -0500
commit06fa6670fb6bf430739cb1f69d28429a0e24851f (patch)
tree34ad99baa997a40742fd378d1dfddfaeef68ba78 /src
parentefeb3135061dd45d3882eadd878ac09943d0362a (diff)
downloadpostgresql-06fa6670fb6bf430739cb1f69d28429a0e24851f.tar.gz
postgresql-06fa6670fb6bf430739cb1f69d28429a0e24851f.zip
Ensure gatherstate->nextreader is properly initialized.
The previously code worked OK as long as a Gather node was never rescanned, or if it was rescanned, as long as it got at least as many workers on rescan as it had originally. But if the number of workers ever decreased on a rescan, then it could crash. Andreas Seltenreich
Diffstat (limited to 'src')
-rw-r--r--src/backend/executor/nodeGather.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/backend/executor/nodeGather.c b/src/backend/executor/nodeGather.c
index 438d1b24fc2..7342aadfbb4 100644
--- a/src/backend/executor/nodeGather.c
+++ b/src/backend/executor/nodeGather.c
@@ -172,6 +172,7 @@ ExecGather(GatherState *node)
if (pcxt->nworkers_launched > 0)
{
node->nreaders = 0;
+ node->nextreader = 0;
node->reader =
palloc(pcxt->nworkers_launched * sizeof(TupleQueueReader *));
@@ -334,6 +335,7 @@ gather_readnext(GatherState *gatherstate)
CHECK_FOR_INTERRUPTS();
/* Attempt to read a tuple, but don't block if none is available. */
+ Assert(gatherstate->nextreader < gatherstate->nreaders);
reader = gatherstate->reader[gatherstate->nextreader];
tup = TupleQueueReaderNext(reader, true, &readerdone);