Skip to content

Commit 227d57f

Browse files
committed
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.
1 parent 7d8db3e commit 227d57f

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/backend/access/transam/parallel.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -513,14 +513,17 @@ DestroyParallelContext(ParallelContext *pcxt)
513513
dlist_delete(&pcxt->node);
514514

515515
/* Kill each worker in turn, and forget their error queues. */
516-
for (i = 0; i < pcxt->nworkers; ++i)
516+
if (pcxt->worker != NULL)
517517
{
518-
if (pcxt->worker[i].bgwhandle != NULL)
519-
TerminateBackgroundWorker(pcxt->worker[i].bgwhandle);
520-
if (pcxt->worker[i].error_mqh != NULL)
518+
for (i = 0; i < pcxt->nworkers; ++i)
521519
{
522-
pfree(pcxt->worker[i].error_mqh);
523-
pcxt->worker[i].error_mqh = NULL;
520+
if (pcxt->worker[i].bgwhandle != NULL)
521+
TerminateBackgroundWorker(pcxt->worker[i].bgwhandle);
522+
if (pcxt->worker[i].error_mqh != NULL)
523+
{
524+
pfree(pcxt->worker[i].error_mqh);
525+
pcxt->worker[i].error_mqh = NULL;
526+
}
524527
}
525528
}
526529

@@ -550,7 +553,7 @@ DestroyParallelContext(ParallelContext *pcxt)
550553
{
551554
BgwHandleStatus status;
552555

553-
if (pcxt->worker[i].bgwhandle == NULL)
556+
if (pcxt->worker == NULL || pcxt->worker[i].bgwhandle == NULL)
554557
continue;
555558

556559
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy