]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix erroneous memory context switch in autovacuum, which was returning to a
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Tue, 20 Jan 2009 12:17:23 +0000 (12:17 +0000)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Tue, 20 Jan 2009 12:17:23 +0000 (12:17 +0000)
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.

src/backend/postmaster/autovacuum.c

index f17b3905d325e9a0c4ff2ce9a5e6d31bd680c0a7..be395aec14ec2bc3dbb039ce303510b202a14280 100644 (file)
@@ -10,7 +10,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.29.2.1 2008/01/17 23:47:04 alvherre Exp $
+ *       $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.29.2.2 2009/01/20 12:17:23 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -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);
 }
 
 /*