From c28bfb35ef6ce9e9d82da00008554d0fc9c4a7fc Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 4 Jun 2013 14:59:02 -0400 Subject: Fix memory leak in LogStandbySnapshot(). The array allocated by GetRunningTransactionLocks() needs to be pfree'd when we're done with it. Otherwise we leak some memory during each checkpoint, if wal_level = hot_standby. This manifests as memory bloat in the checkpointer process, or in bgwriter in versions before we made the checkpointer separate. Reported and fixed by Naoya Anzai. Back-patch to 9.0 where the issue was introduced. In passing, improve comments for GetRunningTransactionLocks(), and add an Assert that we didn't overrun the palloc'd array. --- src/backend/storage/ipc/standby.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'src/backend/storage/ipc/standby.c') diff --git a/src/backend/storage/ipc/standby.c b/src/backend/storage/ipc/standby.c index 1a5481177ad..1db951d1fbc 100644 --- a/src/backend/storage/ipc/standby.c +++ b/src/backend/storage/ipc/standby.c @@ -879,16 +879,11 @@ LogStandbySnapshot(void) /* * Get details of any AccessExclusiveLocks being held at the moment. - * - * XXX GetRunningTransactionLocks() currently holds a lock on all - * partitions though it is possible to further optimise the locking. By - * reference counting locks and storing the value on the ProcArray entry - * for each backend we can easily tell if any locks need recording without - * trying to acquire the partition locks and scanning the lock table. */ locks = GetRunningTransactionLocks(&nlocks); if (nlocks > 0) LogAccessExclusiveLocks(nlocks, locks); + pfree(locks); /* * Log details of all in-progress transactions. This should be the last -- cgit v1.2.3