From daef5212083648c49ee498fc8f2288548fe3b077 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 13 May 1999 00:34:57 +0000 Subject: [PATCH] Release allocated memory during AtAbort_Memory. --- src/backend/access/transam/xact.c | 39 +++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index c8b422d220..7e94d60c01 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -690,13 +690,27 @@ AtCommit_Locks() static void AtCommit_Memory() { + Portal portal; + MemoryContext portalContext; + /* ---------------- - * now that we're "out" of a transaction, have the + * Release memory in the blank portal. + * Since EndPortalAllocMode implicitly works on the current context, + * first make real sure that the blank portal is the selected context. + * (This is probably not necessary, but seems like a good idea...) + * ---------------- + */ + portal = GetPortalByName(NULL); + portalContext = (MemoryContext) PortalGetHeapMemory(portal); + MemoryContextSwitchTo(portalContext); + EndPortalAllocMode(); + + /* ---------------- + * Now that we're "out" of a transaction, have the * system allocate things in the top memory context instead * of the blank portal memory context. * ---------------- */ - EndPortalAllocMode(); MemoryContextSwitchTo(TopMemoryContext); } @@ -770,10 +784,25 @@ AtAbort_Locks() static void AtAbort_Memory() { + Portal portal; + MemoryContext portalContext; + + /* ---------------- + * Release memory in the blank portal. + * Since EndPortalAllocMode implicitly works on the current context, + * first make real sure that the blank portal is the selected context. + * (This is ESSENTIAL in case we aborted from someplace where it wasn't.) + * ---------------- + */ + portal = GetPortalByName(NULL); + portalContext = (MemoryContext) PortalGetHeapMemory(portal); + MemoryContextSwitchTo(portalContext); + EndPortalAllocMode(); + /* ---------------- - * after doing an abort transaction, make certain the - * system uses the top memory context rather then the - * portal memory context (until the next transaction). + * Now that we're "out" of a transaction, have the + * system allocate things in the top memory context instead + * of the blank portal memory context. * ---------------- */ MemoryContextSwitchTo(TopMemoryContext); -- 2.39.5