@@ -1378,7 +1378,7 @@ mXactCachePut(MultiXactId multi, int nmembers, MultiXactMember *members)
13781378{
13791379/* The cache only lives as long as the current transaction */
13801380debug_elog2 (DEBUG2 ,"CachePut: initializing memory context" );
1381- MXactContext = AllocSetContextCreate (TopTransactionContext ,
1381+ MXactContext = AllocSetContextCreate (TopMemoryContext ,
13821382"MultiXact cache context" ,
13831383ALLOCSET_SMALL_SIZES );
13841384}
@@ -1484,7 +1484,11 @@ AtEOXact_MultiXact(void)
14841484 * Discard the local MultiXactId cache. Since MXactContext was created as
14851485 * a child of TopTransactionContext, we needn't delete it explicitly.
14861486 */
1487- MXactContext = NULL ;
1487+ if (MXactContext )
1488+ {
1489+ MemoryContextDelete (MXactContext );
1490+ MXactContext = NULL ;
1491+ }
14881492dlist_init (& MXactCache );
14891493MXactCacheMembers = 0 ;
14901494}
@@ -1551,7 +1555,11 @@ PostPrepare_MultiXact(TransactionId xid)
15511555/*
15521556 * Discard the local MultiXactId cache like in AtEOX_MultiXact
15531557 */
1554- MXactContext = NULL ;
1558+ if (MXactContext )
1559+ {
1560+ MemoryContextDelete (MXactContext );
1561+ MXactContext = NULL ;
1562+ }
15551563dlist_init (& MXactCache );
15561564MXactCacheMembers = 0 ;
15571565}