Skip to content

Commit 945ba50

Browse files
committed
Fix a memory leak in the autovacuum launcher code. Noted by Darcy Buskermolen,
who reported it privately to me.
1 parent 6889303 commit 945ba50

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/backend/postmaster/autovacuum.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
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)
10381038
avw_dbase *avdb;
10391039
TimestampTz current_time;
10401040
bool skipit = false;
1041+
Oid retval = InvalidOid;
1042+
MemoryContext tmpcxt,
1043+
oldcxt;
10411044

10421045
/* return quickly when there are no free workers */
10431046
LWLockAcquire(AutovacuumLock, LW_SHARED);
@@ -1048,6 +1051,17 @@ do_start_worker(void)
10481051
}
10491052
LWLockRelease(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 */
10521066
pgstat_clear_snapshot();
10531067

@@ -1186,7 +1200,7 @@ do_start_worker(void)
11861200

11871201
SendPostmasterSignal(PMSIGNAL_START_AUTOVAC_WORKER);
11881202

1189-
return avdb->adw_datid;
1203+
retval = avdb->adw_datid;
11901204
}
11911205
else if (skipit)
11921206
{
@@ -1197,7 +1211,10 @@ do_start_worker(void)
11971211
rebuild_database_list(InvalidOid);
11981212
}
11991213

1200-
return InvalidOid;
1214+
MemoryContextSwitchTo(oldcxt);
1215+
MemoryContextDelete(tmpcxt);
1216+
1217+
return retval;
12011218
}
12021219

12031220
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy