Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit78dcd02

Browse files
committed
Fix potential memory leakage from HandleParallelMessages().
HandleParallelMessages leaked memory into the caller's context. Since it'scalled from ProcessInterrupts, there is basically zero certainty as to whatCurrentMemoryContext is, which means we could be leaking into long-livedcontexts. Over the processing of many worker messages that would grow tobe a problem. Things could be even worse than just a leak, if we happenedto service the interrupt while ErrorContext is current: elog.c thinks itcan reset that on its own whim, possibly yanking storage out from underHandleParallelMessages.Give HandleParallelMessages its own dedicated context instead, which we canreset during each call to ensure there's no accumulation of wasted memory.Discussion: <16610.1472222135@sss.pgh.pa.us>
1 parent45a36e6 commit78dcd02

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

‎src/backend/access/transam/parallel.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,9 @@ void
702702
HandleParallelMessages(void)
703703
{
704704
dlist_iteriter;
705+
MemoryContextoldcontext;
706+
707+
staticMemoryContexthpm_context=NULL;
705708

706709
/*
707710
* This is invoked from ProcessInterrupts(), and since some of the
@@ -712,6 +715,23 @@ HandleParallelMessages(void)
712715
*/
713716
HOLD_INTERRUPTS();
714717

718+
/*
719+
* Moreover, CurrentMemoryContext might be pointing almost anywhere. We
720+
* don't want to risk leaking data into long-lived contexts, so let's do
721+
* our work here in a private context that we can reset on each use.
722+
*/
723+
if (hpm_context==NULL)/* first time through? */
724+
hpm_context=AllocSetContextCreate(TopMemoryContext,
725+
"HandleParallelMessages context",
726+
ALLOCSET_DEFAULT_MINSIZE,
727+
ALLOCSET_DEFAULT_INITSIZE,
728+
ALLOCSET_DEFAULT_MAXSIZE);
729+
else
730+
MemoryContextReset(hpm_context);
731+
732+
oldcontext=MemoryContextSwitchTo(hpm_context);
733+
734+
/* OK to process messages. Reset the flag saying there are more to do. */
715735
ParallelMessagePending= false;
716736

717737
dlist_foreach(iter,&pcxt_list)
@@ -758,6 +778,11 @@ HandleParallelMessages(void)
758778
}
759779
}
760780

781+
MemoryContextSwitchTo(oldcontext);
782+
783+
/* Might as well clear the context on our way out */
784+
MemoryContextReset(hpm_context);
785+
761786
RESUME_INTERRUPTS();
762787
}
763788

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp