From: Alvaro Herrera Date: Tue, 20 Jan 2009 12:17:23 +0000 (+0000) Subject: Fix erroneous memory context switch in autovacuum, which was returning to a X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=995b608e9e87e4bc68b8421f0f7ee50af5f4380f;p=users%2Fbernd%2Fpostgres.git Fix erroneous memory context switch in autovacuum, which was returning to a context long after it had been destroyed. Per problem report from Justin Pasher. Patch by Tom Lane and me. 8.3 and later do not have this bug, because this code has been restructured for unrelated reasons. In 8.2 it does not manifest as a crash, but it still seems safer fixing it nonetheless. --- diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c index ccf6ea5c33..2b61498872 100644 --- a/src/backend/postmaster/autovacuum.c +++ b/src/backend/postmaster/autovacuum.c @@ -883,13 +883,12 @@ autovacuum_do_vac_analyze(Oid relid, bool dovacuum, bool doanalyze, int freeze_min_age) { VacuumStmt *vacstmt; - MemoryContext old_cxt; /* * The node must survive transaction boundaries, so make sure we create it * in a long-lived context */ - old_cxt = MemoryContextSwitchTo(AutovacMemCxt); + MemoryContextSwitchTo(AutovacMemCxt); vacstmt = makeNode(VacuumStmt); @@ -915,7 +914,9 @@ autovacuum_do_vac_analyze(Oid relid, bool dovacuum, bool doanalyze, vacuum(vacstmt, list_make1_oid(relid)); pfree(vacstmt); - MemoryContextSwitchTo(old_cxt); + + /* Make sure we end up pointing to the long-lived context at exit */ + MemoryContextSwitchTo(AutovacMemCxt); } /*