postgres.git / summary / log / commit / refs

commit    fd640dbb867445b0a58d59dd429f2928a5d7baa8
Author:   Tom Lane <tgl@sss.pgh.pa.us>
Date:     Wed Aug 31 20:23:20 2022 +0000
First released in: 16.0, 10.23, 11.18, 12.13, 13.9, 14.6, 15.0

    Prevent long-term memory leakage in autovacuum launcher.
    
    get_database_list() failed to restore the caller's memory context,
    instead leaving current context set to TopMemoryContext which is
    how CommitTransactionCommand() leaves it.  The callers both think
    they are using short-lived contexts, for the express purpose of
    not having to worry about cleaning up individual allocations.
    The net effect therefore is that supposedly short-lived allocations
    could accumulate indefinitely in the launcher's TopMemoryContext.
    
    Although this has been broken for a long time, it seems we didn't
    have any obvious memory leak here until v15's rearrangement of the
    stats logic.  I (tgl) am not entirely convinced that there's no
    other leak at all, though, and we're surely at risk of adding one
    in future back-patched fixes.  So back-patch to all supported
    branches, even though this may be only a latent bug in pre-v15.
    
    Reid Thompson
    
    Discussion: https://postgr.es/m/972a4e12b68b0f96db514777a150ceef7dcd2e0f.camel@crunchydata.com


src/backend/postmaster/autovacuum.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c index 9d79effa914..ed8f286e44a 100644 --- a/src/backend/postmaster/autovacuum.c +++ b/src/backend/postmaster/autovacuum.c @@ -1932,6 +1932,9 @@ get_database_list(void) CommitTransactionCommand(); + /* Be sure to restore caller's memory context */ + MemoryContextSwitchTo(resultcxt); + return dblist; } [parent: cba393a10af8]