From 124620878224f3293a023afa7b046b2a843f66f3 Mon Sep 17 00:00:00 2001 From: openGaussDev Date: Mon, 7 Mar 2022 15:09:53 +0800 Subject: [PATCH] fix memory leak Offering: openGaussDev More detail: OidRBTree functions should not switch context Match-id-549a0404d2d65dff177f0a2d2d2391f1c158a4da --- src/common/backend/utils/misc/oidrbtree.cpp | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/common/backend/utils/misc/oidrbtree.cpp b/src/common/backend/utils/misc/oidrbtree.cpp index d651a4c64..3d80cdecc 100644 --- a/src/common/backend/utils/misc/oidrbtree.cpp +++ b/src/common/backend/utils/misc/oidrbtree.cpp @@ -26,15 +26,6 @@ #include "utils/oidrbtree.h" #include "utils/memutils.h" -MemoryContext GetOidRBTreeMemory() -{ - if (!t_thrd.security_policy_cxt.OidRBTreeMemoryContext) { - t_thrd.security_policy_cxt.OidRBTreeMemoryContext = AllocSetContextCreate(TopMemoryContext, "OidRBTreeMemory", - ALLOCSET_DEFAULT_MINSIZE, ALLOCSET_DEFAULT_INITSIZE, ALLOCSET_DEFAULT_MAXSIZE); - } - return t_thrd.security_policy_cxt.OidRBTreeMemoryContext; -} - void DeleteOidRBTreeMemory() { if (t_thrd.security_policy_cxt.OidRBTreeMemoryContext != NULL) { @@ -72,9 +63,7 @@ static void OidRBCombine(RBNode* existing, const RBNode* newdata, void* arg) /* Allocator function for oid rbtree */ static RBNode* OidRBAlloc(void* arg) { - MemoryContext oldContext = MemoryContextSwitchTo(GetOidRBTreeMemory()); OidRBNode* oidRBNode = static_cast(palloc(sizeof(OidRBNode))); - (void)MemoryContextSwitchTo(oldContext); return (RBNode*)oidRBNode; } @@ -87,9 +76,7 @@ static void OidRBDealloc(RBNode* rbNode, void* arg) OidRBTree* CreateOidRBTree() { - MemoryContext oldContext = MemoryContextSwitchTo(GetOidRBTreeMemory()); OidRBTree* oidRBTree = rb_create(sizeof(OidRBNode), OidRBComparator, OidRBCombine, OidRBAlloc, OidRBDealloc, NULL); - (void)MemoryContextSwitchTo(oldContext); return oidRBTree; } @@ -97,14 +84,12 @@ static List* OidRBTreeGetNodeList(OidRBTree& oidRBtree) { List* nodeList = NIL; OidRBTree* tree = &oidRBtree; - MemoryContext oldContext = MemoryContextSwitchTo(GetOidRBTreeMemory()); rb_begin_iterate(tree, InvertedWalk); RBNode *node = rb_iterate(tree); while (node != NULL) { nodeList = lappend(nodeList, node); node = rb_iterate(tree); } - (void)MemoryContextSwitchTo(oldContext); return nodeList; }