aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam/parallel.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2015-09-30 18:36:31 -0400
committerRobert Haas <rhaas@postgresql.org>2015-09-30 18:36:31 -0400
commit227d57f3587d7d2a7d0792011f5ac952ba763681 (patch)
treee9d01a3ac99cbb49438f66e3293ef20784e312f6 /src/backend/access/transam/parallel.c
parent7d8db3e8f37aec9d252353904e77381a18a2fa9f (diff)
downloadpostgresql-227d57f3587d7d2a7d0792011f5ac952ba763681.tar.gz
postgresql-227d57f3587d7d2a7d0792011f5ac952ba763681.zip
Don't dump core when destroying an unused ParallelContext.
If a transaction or subtransaction creates a ParallelContext but ends without calling InitializeParallelDSM, the previous code would seg fault. Fix that.
Diffstat (limited to 'src/backend/access/transam/parallel.c')
-rw-r--r--src/backend/access/transam/parallel.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c
index f4ba8518b12..29d6ed57cc2 100644
--- a/src/backend/access/transam/parallel.c
+++ b/src/backend/access/transam/parallel.c
@@ -513,14 +513,17 @@ DestroyParallelContext(ParallelContext *pcxt)
dlist_delete(&pcxt->node);
/* Kill each worker in turn, and forget their error queues. */
- for (i = 0; i < pcxt->nworkers; ++i)
+ if (pcxt->worker != NULL)
{
- if (pcxt->worker[i].bgwhandle != NULL)
- TerminateBackgroundWorker(pcxt->worker[i].bgwhandle);
- if (pcxt->worker[i].error_mqh != NULL)
+ for (i = 0; i < pcxt->nworkers; ++i)
{
- pfree(pcxt->worker[i].error_mqh);
- pcxt->worker[i].error_mqh = NULL;
+ if (pcxt->worker[i].bgwhandle != NULL)
+ TerminateBackgroundWorker(pcxt->worker[i].bgwhandle);
+ if (pcxt->worker[i].error_mqh != NULL)
+ {
+ pfree(pcxt->worker[i].error_mqh);
+ pcxt->worker[i].error_mqh = NULL;
+ }
}
}
@@ -550,7 +553,7 @@ DestroyParallelContext(ParallelContext *pcxt)
{
BgwHandleStatus status;
- if (pcxt->worker[i].bgwhandle == NULL)
+ if (pcxt->worker == NULL || pcxt->worker[i].bgwhandle == NULL)
continue;
/*