]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix inappropriately-timed memory context switch in autovacuum_do_vac_analyze.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 14 Mar 2008 23:49:28 +0000 (23:49 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 14 Mar 2008 23:49:28 +0000 (23:49 +0000)
This accidentally failed to fail before 8.3, because the context we were
switching back to was long-lived anyway; but it sure looks risky as can be
now.  Well spotted by Pavan Deolasee.

src/backend/postmaster/autovacuum.c

index ca0bdde7364d019f6c6308ed9a9c08324be0b50e..b55214e0bc5ce7885ad4262172a632fe37c0bb24 100644 (file)
@@ -55,7 +55,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.73 2008/03/14 17:25:58 alvherre Exp $
+ *       $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.74 2008/03/14 23:49:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -2602,17 +2602,12 @@ autovacuum_do_vac_analyze(Oid relid, bool dovacuum, bool doanalyze,
                                                  BufferAccessStrategy bstrategy)
 {
        VacuumStmt      vacstmt;
+       List       *relids;
        MemoryContext old_cxt;
 
+       /* Set up command parameters --- use a local variable instead of palloc */
        MemSet(&vacstmt, 0, sizeof(vacstmt));
 
-       /*
-        * The list must survive transaction boundaries, so make sure we create it
-        * in a long-lived context
-        */
-       old_cxt = MemoryContextSwitchTo(AutovacMemCxt);
-
-       /* Set up command parameters */
        vacstmt.type = T_VacuumStmt;
        vacstmt.vacuum = dovacuum;
        vacstmt.full = false;
@@ -2622,11 +2617,18 @@ autovacuum_do_vac_analyze(Oid relid, bool dovacuum, bool doanalyze,
        vacstmt.relation = NULL;        /* not used since we pass a relids list */
        vacstmt.va_cols = NIL;
 
+       /*
+        * The list must survive transaction boundaries, so make sure we create it
+        * in a long-lived context
+        */
+       old_cxt = MemoryContextSwitchTo(AutovacMemCxt);
+       relids = list_make1_oid(relid);
+       MemoryContextSwitchTo(old_cxt);
+
        /* Let pgstat know what we're doing */
        autovac_report_activity(&vacstmt, relid);
 
-       vacuum(&vacstmt, list_make1_oid(relid), bstrategy, for_wraparound, true);
-       MemoryContextSwitchTo(old_cxt);
+       vacuum(&vacstmt, relids, bstrategy, for_wraparound, true);
 }
 
 /*