Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5d23463

Browse files
tglsfdcCommitfest Bot
authored and
Commitfest Bot
committed
Fix leaks in load_domaintype_info().
load_domaintype_info() intentionally leaks some intermediate cruft into the long-lived DomainConstraintCache's memory context, reasoning that the amount of leakage will typically not be much so it's not worth doing a copyObject() of the final tree to avoid that. But Valgrind knows nothing of engineering tradeoffs and complains anyway. On the whole, the copyObject doesn't cost that much and this is surely not a performance-critical code path, so let's do it the clean way. Author: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/285483.1746756246@sss.pgh.pa.us
1 parent a48c894 commit 5d23463

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/backend/utils/cache/typcache.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,9 +1171,6 @@ load_domaintype_info(TypeCacheEntry *typentry)
11711171
elog(ERROR, "domain \"%s\" constraint \"%s\" has NULL conbin",
11721172
NameStr(typTup->typname), NameStr(c->conname));
11731173

1174-
/* Convert conbin to C string in caller context */
1175-
constring = TextDatumGetCString(val);
1176-
11771174
/* Create the DomainConstraintCache object and context if needed */
11781175
if (dcc == NULL)
11791176
{
@@ -1189,9 +1186,8 @@ load_domaintype_info(TypeCacheEntry *typentry)
11891186
dcc->dccRefCount = 0;
11901187
}
11911188

1192-
/* Create node trees in DomainConstraintCache's context */
1193-
oldcxt = MemoryContextSwitchTo(dcc->dccContext);
1194-
1189+
/* Convert conbin to a node tree, still in caller's context */
1190+
constring = TextDatumGetCString(val);
11951191
check_expr = (Expr *) stringToNode(constring);
11961192

11971193
/*
@@ -1206,10 +1202,13 @@ load_domaintype_info(TypeCacheEntry *typentry)
12061202
*/
12071203
check_expr = expression_planner(check_expr);
12081204

1205+
/* Create only the minimally needed stuff in dccContext */
1206+
oldcxt = MemoryContextSwitchTo(dcc->dccContext);
1207+
12091208
r = makeNode(DomainConstraintState);
12101209
r->constrainttype = DOM_CONSTRAINT_CHECK;
12111210
r->name = pstrdup(NameStr(c->conname));
1212-
r->check_expr = check_expr;
1211+
r->check_expr = copyObject(check_expr);
12131212
r->check_exprstate = NULL;
12141213

12151214
MemoryContextSwitchTo(oldcxt);

0 commit comments

Comments
 (0)