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

Commit90857b4

Browse files
committed
Preserve caller's memory context in ProcessCompletedNotifies().
This is necessary to avoid long-term memory leakage, because the main loopin PostgresMain expects to be executing in MessageContext, and hence is abit sloppy about freeing stuff that is only needed for the duration ofprocessing the current client message. The known case of an actual leakis when encoding conversion has to be done on the incoming command string,but there might be others. Per report from Per-Olov Esgard.Back-patch to 9.0, where the bug was introduced by the LISTEN/NOTIFYrewrite.
1 parent336db7e commit90857b4

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

‎src/backend/commands/async.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,7 @@ Exec_UnlistenAllCommit(void)
10901090
void
10911091
ProcessCompletedNotifies(void)
10921092
{
1093+
MemoryContextcaller_context;
10931094
boolsignalled;
10941095

10951096
/* Nothing to do if we didn't send any notifications */
@@ -1103,6 +1104,12 @@ ProcessCompletedNotifies(void)
11031104
*/
11041105
backendHasSentNotifications= false;
11051106

1107+
/*
1108+
* We must preserve the caller's memory context (probably MessageContext)
1109+
* across the transaction we do here.
1110+
*/
1111+
caller_context=CurrentMemoryContext;
1112+
11061113
if (Trace_notify)
11071114
elog(DEBUG1,"ProcessCompletedNotifies");
11081115

@@ -1135,6 +1142,8 @@ ProcessCompletedNotifies(void)
11351142

11361143
CommitTransactionCommand();
11371144

1145+
MemoryContextSwitchTo(caller_context);
1146+
11381147
/* We don't need pq_flush() here since postgres.c will do one shortly */
11391148
}
11401149

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp