Content-Length: 287831 | pFad | http://github.com/postgrespro/postgres/commit/1452a0bb87c78812372f103de14cb6492a932ac6

80 Don't run RelationInitTableAccessMethod in a long-lived context. · postgrespro/postgres@1452a0b · GitHub
Skip to content

Commit 1452a0b

Browse 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 fbcc9fe commit 1452a0b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/backend/utils/cache/relcache.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3359,6 +3359,13 @@ RelationBuildLocalRelation(const char *relname,
33593359

33603360
rel->rd_rel->relam = accessmtd;
33613361

3362+
/*
3363+
* RelationInitTableAccessMethod will do syscache lookups, so we mustn't
3364+
* run it in CacheMemoryContext. Fortunately, the remaining steps don't
3365+
* require a long-lived current context.
3366+
*/
3367+
MemoryContextSwitchTo(oldcxt);
3368+
33623369
if (relkind == RELKIND_RELATION ||
33633370
relkind == RELKIND_SEQUENCE ||
33643371
relkind == RELKIND_TOASTVALUE ||
@@ -3382,11 +3389,6 @@ RelationBuildLocalRelation(const char *relname,
33823389
*/
33833390
EOXactListAdd(rel);
33843391

3385-
/*
3386-
* done building relcache entry.
3387-
*/
3388-
MemoryContextSwitchTo(oldcxt);
3389-
33903392
/* It's fully valid */
33913393
rel->rd_isvalid = true;
33923394

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgrespro/postgres/commit/1452a0bb87c78812372f103de14cb6492a932ac6

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy