diff options
author | Tom Lane | 2022-08-31 20:23:20 +0000 |
---|---|---|
committer | Tom Lane | 2022-08-31 20:23:35 +0000 |
commit | 1c1294be716d96e804aadafc249fcbfa8367621d (patch) | |
tree | 2b07aeb011e728d7dfc5969dc0f60507bb596253 | |
parent | c3ffa731a5f99c4361203015ce2219d209fea94c (diff) |
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/[email protected]
-rw-r--r-- | src/backend/postmaster/autovacuum.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c index b3b1afba861..9dc6bf9477f 100644 --- a/src/backend/postmaster/autovacuum.c +++ b/src/backend/postmaster/autovacuum.c @@ -1941,6 +1941,9 @@ get_database_list(void) CommitTransactionCommand(); + /* Be sure to restore caller's memory context */ + MemoryContextSwitchTo(resultcxt); + return dblist; } |