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

Appearance settings

Commit ea3989f

Browse filesBrowse files
committed
Don't run RelationInitTableAccessMethod in a long-lived context.
Some code paths in this function perform syscache lookups, which can lead to table accesses and possibly leakage of cruft into the caller's context. If said context is CacheMemoryContext, we eventually will have visible bloat. But fixing this is no harder than moving one memory context switch step. (The other callers don't have a problem.) Andres Freund and I independently found this via valgrind testing. Back-patch to v12 where this code was added. Discussion: https://postgr.es/m/20210317023101.anvejcfotwka6gaa@alap3.anarazel.de Discussion: https://postgr.es/m/3816764.1616104288@sss.pgh.pa.us
1 parent 5368369 commit ea3989f
Copy full SHA for ea3989f

File tree

Expand file treeCollapse file tree

1 file changed

+7
-5
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+7
-5
lines changed

‎src/backend/utils/cache/relcache.c

Copy file name to clipboardExpand all lines: src/backend/utils/cache/relcache.c
+7-5Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3529,6 +3529,13 @@ RelationBuildLocalRelation(const char *relname,
35293529

35303530
rel->rd_rel->relam = accessmtd;
35313531

3532+
/*
3533+
* RelationInitTableAccessMethod will do syscache lookups, so we mustn't
3534+
* run it in CacheMemoryContext. Fortunately, the remaining steps don't
3535+
* require a long-lived current context.
3536+
*/
3537+
MemoryContextSwitchTo(oldcxt);
3538+
35323539
if (relkind == RELKIND_RELATION ||
35333540
relkind == RELKIND_SEQUENCE ||
35343541
relkind == RELKIND_TOASTVALUE ||
@@ -3552,11 +3559,6 @@ RelationBuildLocalRelation(const char *relname,
35523559
*/
35533560
EOXactListAdd(rel);
35543561

3555-
/*
3556-
* done building relcache entry.
3557-
*/
3558-
MemoryContextSwitchTo(oldcxt);
3559-
35603562
/* It's fully valid */
35613563
rel->rd_isvalid = true;
35623564

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.