5555 *
5656 *
5757 * IDENTIFICATION
58- * $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.57 2007/09/11 17:15:33 tgl Exp $
58+ * $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.58 2007/09/12 22:14:59 alvherre Exp $
5959 *
6060 *-------------------------------------------------------------------------
6161 */
@@ -1038,6 +1038,9 @@ do_start_worker(void)
10381038avw_dbase * avdb ;
10391039TimestampTz current_time ;
10401040bool skipit = false;
1041+ Oid retval = InvalidOid ;
1042+ MemoryContext tmpcxt ,
1043+ oldcxt ;
10411044
10421045/* return quickly when there are no free workers */
10431046LWLockAcquire (AutovacuumLock ,LW_SHARED );
@@ -1048,6 +1051,17 @@ do_start_worker(void)
10481051}
10491052LWLockRelease (AutovacuumLock );
10501053
1054+ /*
1055+ * Create and switch to a temporary context to avoid leaking the memory
1056+ * allocated for the database list.
1057+ */
1058+ tmpcxt = AllocSetContextCreate (CurrentMemoryContext ,
1059+ "Start worker tmp cxt" ,
1060+ ALLOCSET_DEFAULT_MINSIZE ,
1061+ ALLOCSET_DEFAULT_INITSIZE ,
1062+ ALLOCSET_DEFAULT_MAXSIZE );
1063+ oldcxt = MemoryContextSwitchTo (tmpcxt );
1064+
10511065/* use fresh stats */
10521066pgstat_clear_snapshot ();
10531067
@@ -1186,7 +1200,7 @@ do_start_worker(void)
11861200
11871201SendPostmasterSignal (PMSIGNAL_START_AUTOVAC_WORKER );
11881202
1189- return avdb -> adw_datid ;
1203+ retval = avdb -> adw_datid ;
11901204}
11911205else if (skipit )
11921206{
@@ -1197,7 +1211,10 @@ do_start_worker(void)
11971211rebuild_database_list (InvalidOid );
11981212}
11991213
1200- return InvalidOid ;
1214+ MemoryContextSwitchTo (oldcxt );
1215+ MemoryContextDelete (tmpcxt );
1216+
1217+ return retval ;
12011218}
12021219
12031220/*