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

Commit1dde578

Browse files
committed
Clean up data conversion short-lived memory context.
dblink uses a short-lived data conversion memory context. However itwas not deleted when no longer needed, leading to a noticeable memoryleak under some circumstances. Plug the hole, along with minorrefactoring. Backpatch to 9.2 where the leak was introduced.Report and initial patch by MauMau. Reviewed/modified slightly byTom Lane and me.
1 parentecac0e2 commit1dde578

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

‎contrib/dblink/dblink.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,13 @@ materializeQueryResult(FunctionCallInfo fcinfo,
977977

978978
PG_TRY();
979979
{
980+
/* Create short-lived memory context for data conversions */
981+
sinfo.tmpcontext=AllocSetContextCreate(CurrentMemoryContext,
982+
"dblink temporary context",
983+
ALLOCSET_DEFAULT_MINSIZE,
984+
ALLOCSET_DEFAULT_INITSIZE,
985+
ALLOCSET_DEFAULT_MAXSIZE);
986+
980987
/* execute query, collecting any tuples into the tuplestore */
981988
res=storeQueryResult(&sinfo,conn,sql);
982989

@@ -1041,6 +1048,12 @@ materializeQueryResult(FunctionCallInfo fcinfo,
10411048
PQclear(res);
10421049
res=NULL;
10431050
}
1051+
1052+
/* clean up data conversion short-lived memory context */
1053+
if (sinfo.tmpcontext!=NULL)
1054+
MemoryContextDelete(sinfo.tmpcontext);
1055+
sinfo.tmpcontext=NULL;
1056+
10441057
PQclear(sinfo.last_res);
10451058
sinfo.last_res=NULL;
10461059
PQclear(sinfo.cur_res);
@@ -1204,15 +1217,6 @@ storeRow(storeInfo *sinfo, PGresult *res, bool first)
12041217
if (sinfo->cstrs)
12051218
pfree(sinfo->cstrs);
12061219
sinfo->cstrs= (char**)palloc(nfields*sizeof(char*));
1207-
1208-
/* Create short-lived memory context for data conversions */
1209-
if (!sinfo->tmpcontext)
1210-
sinfo->tmpcontext=
1211-
AllocSetContextCreate(CurrentMemoryContext,
1212-
"dblink temporary context",
1213-
ALLOCSET_DEFAULT_MINSIZE,
1214-
ALLOCSET_DEFAULT_INITSIZE,
1215-
ALLOCSET_DEFAULT_MAXSIZE);
12161220
}
12171221

12181222
/* Should have a single-row result if we get here */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp