fix memory leak

Offering: openGaussDev

More detail: OidRBTree functions should not switch context

Match-id-549a0404d2d65dff177f0a2d2d2391f1c158a4da
This commit is contained in:
openGaussDev 2022-03-07 15:09:53 +08:00 committed by yanghao
parent 1062a1c1f6
commit 1246208782
1 changed files with 0 additions and 15 deletions

View File

@ -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<OidRBNode*>(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;
}