Skip to content

Commit 5bc0d31

Browse files
committed
Repair incorrect cleanup of heap memory allocation during
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...
1 parent 8b8db01 commit 5bc0d31

File tree

3 files changed

+9
-21
lines changed

3 files changed

+9
-21
lines changed

src/backend/access/transam/xact.c

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.50 1999/09/05 17:12:34 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.51 1999/09/09 16:25:35 tgl Exp $
1111
*
1212
* NOTES
1313
* Transaction aborts can now occur two ways:
@@ -694,19 +694,13 @@ static void
694694
AtCommit_Memory()
695695
{
696696
Portal portal;
697-
MemoryContext portalContext;
698697

699698
/* ----------------
700-
* Release memory in the blank portal.
701-
* Since EndPortalAllocMode implicitly works on the current context,
702-
* first make real sure that the blank portal is the selected context.
703-
* (This is probably not necessary, but seems like a good idea...)
699+
* Release all heap memory in the blank portal.
704700
* ----------------
705701
*/
706702
portal = GetPortalByName(NULL);
707-
portalContext = (MemoryContext) PortalGetHeapMemory(portal);
708-
MemoryContextSwitchTo(portalContext);
709-
EndPortalAllocMode();
703+
PortalResetHeapMemory(portal);
710704

711705
/* ----------------
712706
* Now that we're "out" of a transaction, have the
@@ -784,19 +778,13 @@ static void
784778
AtAbort_Memory()
785779
{
786780
Portal portal;
787-
MemoryContext portalContext;
788781

789782
/* ----------------
790-
* Release memory in the blank portal.
791-
* Since EndPortalAllocMode implicitly works on the current context,
792-
* first make real sure that the blank portal is the selected context.
793-
* (This is ESSENTIAL in case we aborted from someplace where it wasn't.)
783+
* Release all heap memory in the blank portal.
794784
* ----------------
795785
*/
796786
portal = GetPortalByName(NULL);
797-
portalContext = (MemoryContext) PortalGetHeapMemory(portal);
798-
MemoryContextSwitchTo(portalContext);
799-
EndPortalAllocMode();
787+
PortalResetHeapMemory(portal);
800788

801789
/* ----------------
802790
* Now that we're "out" of a transaction, have the

src/backend/utils/mmgr/portalmem.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/mmgr/portalmem.c,v 1.28 1999/07/17 20:18:15 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/mmgr/portalmem.c,v 1.29 1999/09/09 16:25:29 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -83,7 +83,6 @@
8383
static void CollectNamedPortals(Portal *portalP, int destroy);
8484
static Portal PortalHeapMemoryGetPortal(PortalHeapMemory context);
8585
static PortalVariableMemory PortalHeapMemoryGetVariableMemory(PortalHeapMemory context);
86-
static void PortalResetHeapMemory(Portal portal);
8786
static Portal PortalVariableMemoryGetPortal(PortalVariableMemory context);
8887

8988
/* ----------------
@@ -838,7 +837,7 @@ PortalDestroy(Portal *portalP)
838837
* BadArg if mode is invalid.
839838
* ----------------
840839
*/
841-
static void
840+
void
842841
PortalResetHeapMemory(Portal portal)
843842
{
844843
PortalHeapMemory context;

src/include/utils/portal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: portal.h,v 1.17 1999/07/15 23:04:23 momjian Exp $
9+
* $Id: portal.h,v 1.18 1999/09/09 16:25:23 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -75,6 +75,7 @@ extern Portal CreatePortal(char *name);
7575
extern void PortalDestroy(Portal *portalP);
7676
extern void StartPortalAllocMode(AllocMode mode, Size limit);
7777
extern void EndPortalAllocMode(void);
78+
extern void PortalResetHeapMemory(Portal portal);
7879
extern PortalVariableMemory PortalGetVariableMemory(Portal portal);
7980
extern PortalHeapMemory PortalGetHeapMemory(Portal portal);
8081

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy