Index: src/backend/postmaster/autovacuum.c
===================================================================
RCS file: /home/alvherre/Code/cvs/pgsql/src/backend/postmaster/autovacuum.c,v
retrieving revision 1.5.2.8
diff -c -p -r1.5.2.8 autovacuum.c
*** src/backend/postmaster/autovacuum.c	17 Jan 2008 23:47:07 -0000	1.5.2.8
--- src/backend/postmaster/autovacuum.c	17 Jan 2009 04:08:44 -0000
*************** autovacuum_do_vac_analyze(List *relids, 
*** 925,937 ****
  						  bool freeze)
  {
  	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);
  
  	vacstmt = makeNode(VacuumStmt);
  
--- 925,936 ----
  						  bool freeze)
  {
  	VacuumStmt *vacstmt;
  
  	/*
  	 * The node must survive transaction boundaries, so make sure we create it
  	 * in a long-lived context
  	 */
! 	MemoryContextSwitchTo(AutovacMemCxt);
  
  	vacstmt = makeNode(VacuumStmt);
  
*************** autovacuum_do_vac_analyze(List *relids, 
*** 957,963 ****
  	vacuum(vacstmt, relids);
  
  	pfree(vacstmt);
! 	MemoryContextSwitchTo(old_cxt);
  }
  
  /*
--- 956,964 ----
  	vacuum(vacstmt, relids);
  
  	pfree(vacstmt);
! 
! 	/* Make sure we end up pointing to a valid memory context at exit */
! 	MemoryContextSwitchTo(TopTransactionContext);
  }
  
  /*
