Repair incorrect cleanup of heap memory allocation during
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 9 Sep 1999 16:29:22 +0000 (16:29 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 9 Sep 1999 16:29:22 +0000 (16:29 +0000)
transaction abort --- before it only worked if there was exactly one level
of allocation context stacked in the blank portal.  Now it does the right
thing for any depth, including zero...

src/backend/access/transam/xact.c
src/backend/utils/mmgr/portalmem.c
src/include/utils/portal.h

index eb0b058249b7e27af25f24f998d99c7f35772210..a4d54f7ce9743cd520cb7e8e3da47e244224eb9e 100644 (file)
@@ -693,19 +693,13 @@ static void
 AtCommit_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 probably not necessary, but seems like a good idea...)
+        *      Release all heap memory in the blank portal.
         * ----------------
         */
        portal = GetPortalByName(NULL);
-       portalContext = (MemoryContext) PortalGetHeapMemory(portal);
-       MemoryContextSwitchTo(portalContext);
-       EndPortalAllocMode();
+       PortalResetHeapMemory(portal);
 
        /* ----------------
         *      Now that we're "out" of a transaction, have the
@@ -782,19 +776,13 @@ 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.)
+        *      Release all heap memory in the blank portal.
         * ----------------
         */
        portal = GetPortalByName(NULL);
-       portalContext = (MemoryContext) PortalGetHeapMemory(portal);
-       MemoryContextSwitchTo(portalContext);
-       EndPortalAllocMode();
+       PortalResetHeapMemory(portal);
 
        /* ----------------
         *      Now that we're "out" of a transaction, have the
index 9d1f2d12ec32a7288dd8fc83a3756520a3c87fab..fa9c23f08a4f8f8db01b0e562aa3fd86c2613e56 100644 (file)
@@ -83,7 +83,6 @@
 static void CollectNamedPortals(Portal *portalP, int destroy);
 static Portal PortalHeapMemoryGetPortal(PortalHeapMemory context);
 static PortalVariableMemory PortalHeapMemoryGetVariableMemory(PortalHeapMemory context);
-static void PortalResetHeapMemory(Portal portal);
 static Portal PortalVariableMemoryGetPortal(PortalVariableMemory context);
 
 /* ----------------
@@ -838,7 +837,7 @@ PortalDestroy(Portal *portalP)
  *             BadArg if mode is invalid.
  * ----------------
  */
-static void
+void
 PortalResetHeapMemory(Portal portal)
 {
        PortalHeapMemory context;
index 1d7812f7d5cef1874ea4c581de3e8db60ff2c169..260545840a1cbc0bdb8ce58aa5d83136a419e13f 100644 (file)
@@ -75,6 +75,7 @@ extern Portal CreatePortal(char *name);
 extern void PortalDestroy(Portal *portalP);
 extern void StartPortalAllocMode(AllocMode mode, Size limit);
 extern void EndPortalAllocMode(void);
+extern void PortalResetHeapMemory(Portal portal);
 extern PortalVariableMemory PortalGetVariableMemory(Portal portal);
 extern PortalHeapMemory PortalGetHeapMemory(Portal portal);