Prevent long-term memory age in autovacuum launcher.
authorTom Lane <[email protected]>
Wed, 31 Aug 2022 20:23:20 +0000 (16:23 -0400)
committerTom Lane <[email protected]>
Wed, 31 Aug 2022 20:23:35 +0000 (16:23 -0400)
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  here until v15's rearrangement of the
stats logic.  I (tgl) am not entirely convinced that there's no
other  at all, though, and we're surely at risk of adding one
in future back-ed fixes.  So back- to all supported
branches, even though this may be only a latent bug in pre-v15.

Reid Thompson

Discussion: https://postgr.es/m/972a4e12b68b0f96db514777a150ceef7dcd2e0f[email protected]

src/backend/postmaster/autovacuum.c

index b3b1afba86183c02f5915f03547fba1d910f4a96..9dc6bf9477f16040892d33fd58df79239e208259 100644 (file)
@@ -1941,6 +1941,9 @@ get_database_list(void)
 
    CommitTransactionCommand();
 
+   /* Be sure to restore caller's memory context */
+   MemoryContextSwitchTo(resultcxt);
+
    return dblist;
 }