Repair incorrect cleanup of heap memory allocation during
authorTom Lane <[email protected]>
Thu, 9 Sep 1999 16:29:22 +0000 (16:29 +0000)
committerTom Lane <[email protected]>
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 7eb40c9ab9c591ce8868926a524094419a83d577..a4e7348c538f1120aedfc424a3544691724c4fdf 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.42.2.2 1999/08/08 20:24:12 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.42.2.3 1999/09/09 16:29:22 tgl Exp $
  *
  * NOTES
  *     Transaction aborts can now occur two ways:
@@ -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 89fd6dba69b585126f51a5c23dded2f57f5087d3..703a95b76af8ce56f28aa21986f1e6634706b527 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/utils/mmgr/portalmem.c,v 1.23.2.1 1999/08/02 05:25:16 scrappy Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/utils/mmgr/portalmem.c,v 1.23.2.2 1999/09/09 16:29:16 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -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 6bf8e9d778ba385e673215d42ad953ac42f6021a..7376bd9532374f7cfc5d48fab1a986acbc80dfc4 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: portal.h,v 1.15.2.1 1999/08/02 05:25:26 scrappy Exp $
+ * $Id: portal.h,v 1.15.2.2 1999/09/09 16:29:10 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -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);