From eea65943c605215456d0f55f65e1ec802f5e221e Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Tue, 7 Aug 2012 16:59:42 -0400 Subject: [PATCH] Fix memory leaks in event trigger code. Spotted by Jeff Davis. --- src/backend/utils/cache/evtcache.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/backend/utils/cache/evtcache.c b/src/backend/utils/cache/evtcache.c index 565dc449d1..fc9f694e5a 100644 --- a/src/backend/utils/cache/evtcache.c +++ b/src/backend/utils/cache/evtcache.c @@ -84,7 +84,7 @@ BuildEventTriggerCache(void) * the cache failed, then there might be some junk lying around * that we want to reclaim. */ - MemoryContextReset(EventTriggerCacheContext); + MemoryContextResetAndDeleteChildren(EventTriggerCacheContext); } else { @@ -119,8 +119,9 @@ BuildEventTriggerCache(void) ctl.keysize = sizeof(EventTriggerEvent); ctl.entrysize = sizeof(EventTriggerCacheEntry); ctl.hash = tag_hash; + ctl.hcxt = EventTriggerCacheContext; cache = hash_create("Event Trigger Cache", 32, &ctl, - HASH_ELEM | HASH_FUNCTION); + HASH_ELEM | HASH_FUNCTION | HASH_CONTEXT); /* * Prepare to scan pg_event_trigger in name order. We use an MVCC @@ -237,6 +238,6 @@ DecodeTextArrayToCString(Datum array, char ***cstringp) static void InvalidateEventCacheCallback(Datum arg, int cacheid, uint32 hashvalue) { - MemoryContextReset(EventTriggerCacheContext); + MemoryContextResetAndDeleteChildren(EventTriggerCacheContext); EventTriggerCache = NULL; }