Fix a memory leak in the autovacuum launcher code. Noted by Darcy Buskermolen,

who reported it privately to me.
This commit is contained in:
Alvaro Herrera 2007-09-12 22:14:59 +00:00
parent 6889303531
commit 945ba50dc3

View File

@ -55,7 +55,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.57 2007/09/11 17:15:33 tgl Exp $ * $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.58 2007/09/12 22:14:59 alvherre Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -1038,6 +1038,9 @@ do_start_worker(void)
avw_dbase *avdb; avw_dbase *avdb;
TimestampTz current_time; TimestampTz current_time;
bool skipit = false; bool skipit = false;
Oid retval = InvalidOid;
MemoryContext tmpcxt,
oldcxt;
/* return quickly when there are no free workers */ /* return quickly when there are no free workers */
LWLockAcquire(AutovacuumLock, LW_SHARED); LWLockAcquire(AutovacuumLock, LW_SHARED);
@ -1048,6 +1051,17 @@ do_start_worker(void)
} }
LWLockRelease(AutovacuumLock); LWLockRelease(AutovacuumLock);
/*
* Create and switch to a temporary context to avoid leaking the memory
* allocated for the database list.
*/
tmpcxt = AllocSetContextCreate(CurrentMemoryContext,
"Start worker tmp cxt",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
oldcxt = MemoryContextSwitchTo(tmpcxt);
/* use fresh stats */ /* use fresh stats */
pgstat_clear_snapshot(); pgstat_clear_snapshot();
@ -1186,7 +1200,7 @@ do_start_worker(void)
SendPostmasterSignal(PMSIGNAL_START_AUTOVAC_WORKER); SendPostmasterSignal(PMSIGNAL_START_AUTOVAC_WORKER);
return avdb->adw_datid; retval = avdb->adw_datid;
} }
else if (skipit) else if (skipit)
{ {
@ -1197,7 +1211,10 @@ do_start_worker(void)
rebuild_database_list(InvalidOid); rebuild_database_list(InvalidOid);
} }
return InvalidOid; MemoryContextSwitchTo(oldcxt);
MemoryContextDelete(tmpcxt);
return retval;
} }
/* /*