Don't dump core when destroying an unused ParallelContext.
authorRobert Haas <[email protected]>
Wed, 30 Sep 2015 22:36:31 +0000 (18:36 -0400)
committerRobert Haas <[email protected]>
Wed, 30 Sep 2015 22:36:31 +0000 (18:36 -0400)
If a transaction or subtransaction creates a ParallelContext but ends
without calling InitializeParallelDSM, the previous code would
seg fault.  Fix that.

src/backend/access/transam/parallel.c

index f4ba8518b1215d218dc1b8561f6ad83fe9f9bdc5..29d6ed57cc251b290104c3a8faae5ab3c8302567 100644 (file)
@@ -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;
 
                /*