8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 18:43:03 +01:00

Fixed incorrect pools usage leading to memory leaks.

This commit is contained in:
hvlad 2021-07-03 11:46:52 +03:00
parent f24a38d7a9
commit 6de4f3f9db

View File

@ -1265,7 +1265,7 @@ void ExtEngineManager::closeAttachment(thread_db* tdbb, Attachment* attachment)
if (close) if (close)
{ {
if (engines.remove(accessor.current()->first)) // If engine has already been deleted - nothing to do if (engines.remove(accessor.current()->first)) // If engine has already been deleted - nothing to do
engine->release(); PluginManagerInterfacePtr()->releasePlugin(engine);
} }
} }
@ -1288,8 +1288,7 @@ void ExtEngineManager::makeFunction(thread_db* tdbb, CompilerScratch* csb, Jrd::
CallerName(obj_udf, udf->getName().identifier, userName) : CallerName(obj_udf, udf->getName().identifier, userName) :
CallerName(obj_package_header, udf->getName().package, userName))); CallerName(obj_package_header, udf->getName().package, userName)));
///MemoryPool& pool = *tdbb->getDefaultPool(); MemoryPool& pool = *tdbb->getAttachment()->att_pool;
MemoryPool& pool = *getDefaultMemoryPool();
AutoPtr<RoutineMetadata> metadata(FB_NEW_POOL(pool) RoutineMetadata(pool)); AutoPtr<RoutineMetadata> metadata(FB_NEW_POOL(pool) RoutineMetadata(pool));
metadata->package = udf->getName().package; metadata->package = udf->getName().package;
@ -1338,13 +1337,15 @@ void ExtEngineManager::makeFunction(thread_db* tdbb, CompilerScratch* csb, Jrd::
try try
{ {
udf->fun_external = FB_NEW_POOL(getPool()) Function(tdbb, this, attInfo->engine, udf->fun_external = FB_NEW_POOL(pool) Function(tdbb, this, attInfo->engine,
metadata.release(), externalFunction, udf); metadata.release(), externalFunction, udf);
CompoundStmtNode* mainNode = FB_NEW_POOL(getPool()) CompoundStmtNode(getPool()); MemoryPool& csbPool = csb->csb_pool;
CompoundStmtNode* mainNode = FB_NEW_POOL(csbPool) CompoundStmtNode(csbPool);
IntMessageNode* intInMessageNode = udf->getInputFields().hasData() ? IntMessageNode* intInMessageNode = udf->getInputFields().hasData() ?
FB_NEW_POOL(getPool()) IntMessageNode(tdbb, getPool(), csb, 0, FB_NEW_POOL(csbPool) IntMessageNode(tdbb, csbPool, csb, 0,
udf->getInputFields(), udf->getInputFormat()) : udf->getInputFields(), udf->getInputFormat()) :
NULL; NULL;
ExtMessageNode* extInMessageNode = NULL; ExtMessageNode* extInMessageNode = NULL;
@ -1353,38 +1354,38 @@ void ExtEngineManager::makeFunction(thread_db* tdbb, CompilerScratch* csb, Jrd::
{ {
mainNode->statements.add(intInMessageNode); mainNode->statements.add(intInMessageNode);
extInMessageNode = FB_NEW_POOL(getPool()) ExtMessageNode(tdbb, getPool(), csb, 2, extInputFormat); extInMessageNode = FB_NEW_POOL(csbPool) ExtMessageNode(tdbb, csbPool, csb, 2, extInputFormat);
mainNode->statements.add(extInMessageNode); mainNode->statements.add(extInMessageNode);
} }
IntMessageNode* intOutMessageNode = FB_NEW_POOL(getPool()) IntMessageNode(tdbb, getPool(), csb, 1, IntMessageNode* intOutMessageNode = FB_NEW_POOL(csbPool) IntMessageNode(tdbb, csbPool, csb, 1,
udf->getOutputFields(), udf->getOutputFormat()); udf->getOutputFields(), udf->getOutputFormat());
mainNode->statements.add(intOutMessageNode); mainNode->statements.add(intOutMessageNode);
ExtMessageNode* extOutMessageNode = FB_NEW_POOL(getPool()) ExtMessageNode(tdbb, getPool(), csb, 3, ExtMessageNode* extOutMessageNode = FB_NEW_POOL(csbPool) ExtMessageNode(tdbb, csbPool, csb, 3,
extOutputFormat); extOutputFormat);
mainNode->statements.add(extOutMessageNode); mainNode->statements.add(extOutMessageNode);
// Initialize the output fields into the external message. // Initialize the output fields into the external message.
InitOutputNode* initOutputNode = FB_NEW_POOL(getPool()) InitOutputNode( InitOutputNode* initOutputNode = FB_NEW_POOL(csbPool) InitOutputNode(
tdbb, getPool(), csb, udf->getOutputFields(), extOutMessageNode); tdbb, csbPool, csb, udf->getOutputFields(), extOutMessageNode);
mainNode->statements.add(initOutputNode); mainNode->statements.add(initOutputNode);
if (intInMessageNode) if (intInMessageNode)
{ {
ReceiveNode* receiveNode = intInMessageNode ? FB_NEW_POOL(getPool()) ReceiveNode(getPool()) : NULL; ReceiveNode* receiveNode = intInMessageNode ? FB_NEW_POOL(csbPool) ReceiveNode(csbPool) : NULL;
receiveNode->message = intInMessageNode; receiveNode->message = intInMessageNode;
receiveNode->statement = FB_NEW_POOL(getPool()) MessageMoverNode( receiveNode->statement = FB_NEW_POOL(csbPool) MessageMoverNode(
getPool(), intInMessageNode, extInMessageNode); csbPool, intInMessageNode, extInMessageNode);
mainNode->statements.add(receiveNode); mainNode->statements.add(receiveNode);
} }
ExtFunctionNode* extFunctionNode = FB_NEW_POOL(getPool()) ExtFunctionNode(getPool(), ExtFunctionNode* extFunctionNode = FB_NEW_POOL(csbPool) ExtFunctionNode(csbPool,
extInMessageNode, extOutMessageNode, udf->fun_external); extInMessageNode, extOutMessageNode, udf->fun_external);
mainNode->statements.add(extFunctionNode); mainNode->statements.add(extFunctionNode);
extFunctionNode->message = intOutMessageNode; extFunctionNode->message = intOutMessageNode;
extFunctionNode->statement = FB_NEW_POOL(getPool()) MessageMoverNode( extFunctionNode->statement = FB_NEW_POOL(csbPool) MessageMoverNode(
getPool(), extOutMessageNode, intOutMessageNode); csbPool, extOutMessageNode, intOutMessageNode);
JrdStatement* statement = udf->getStatement(); JrdStatement* statement = udf->getStatement();
PAR_preparsed_node(tdbb, NULL, mainNode, NULL, &csb, &statement, false, 0); PAR_preparsed_node(tdbb, NULL, mainNode, NULL, &csb, &statement, false, 0);
@ -1412,8 +1413,7 @@ void ExtEngineManager::makeProcedure(thread_db* tdbb, CompilerScratch* csb, jrd_
CallerName(obj_procedure, prc->getName().identifier, userName) : CallerName(obj_procedure, prc->getName().identifier, userName) :
CallerName(obj_package_header, prc->getName().package, userName))); CallerName(obj_package_header, prc->getName().package, userName)));
///MemoryPool& pool = *tdbb->getDefaultPool(); MemoryPool& pool = *tdbb->getAttachment()->att_pool;
MemoryPool& pool = *getDefaultMemoryPool();
AutoPtr<RoutineMetadata> metadata(FB_NEW_POOL(pool) RoutineMetadata(pool)); AutoPtr<RoutineMetadata> metadata(FB_NEW_POOL(pool) RoutineMetadata(pool));
metadata->package = prc->getName().package; metadata->package = prc->getName().package;
@ -1463,13 +1463,15 @@ void ExtEngineManager::makeProcedure(thread_db* tdbb, CompilerScratch* csb, jrd_
try try
{ {
prc->setExternal(FB_NEW_POOL(getPool()) Procedure(tdbb, this, attInfo->engine, prc->setExternal(FB_NEW_POOL(pool) Procedure(tdbb, this, attInfo->engine,
metadata.release(), externalProcedure, prc)); metadata.release(), externalProcedure, prc));
CompoundStmtNode* mainNode = FB_NEW_POOL(getPool()) CompoundStmtNode(getPool()); MemoryPool& csbPool = csb->csb_pool;
CompoundStmtNode* mainNode = FB_NEW_POOL(csbPool) CompoundStmtNode(csbPool);
IntMessageNode* intInMessageNode = prc->getInputFields().hasData() ? IntMessageNode* intInMessageNode = prc->getInputFields().hasData() ?
FB_NEW_POOL(getPool()) IntMessageNode(tdbb, getPool(), csb, 0, FB_NEW_POOL(csbPool) IntMessageNode(tdbb, csbPool, csb, 0,
prc->getInputFields(), prc->getInputFormat()) : prc->getInputFields(), prc->getInputFormat()) :
NULL; NULL;
ExtMessageNode* extInMessageNode = NULL; ExtMessageNode* extInMessageNode = NULL;
@ -1478,32 +1480,32 @@ void ExtEngineManager::makeProcedure(thread_db* tdbb, CompilerScratch* csb, jrd_
{ {
mainNode->statements.add(intInMessageNode); mainNode->statements.add(intInMessageNode);
extInMessageNode = FB_NEW_POOL(getPool()) ExtMessageNode(tdbb, getPool(), csb, 2, extInputFormat); extInMessageNode = FB_NEW_POOL(csbPool) ExtMessageNode(tdbb, csbPool, csb, 2, extInputFormat);
mainNode->statements.add(extInMessageNode); mainNode->statements.add(extInMessageNode);
} }
IntMessageNode* intOutMessageNode = FB_NEW_POOL(getPool()) IntMessageNode(tdbb, getPool(), csb, 1, IntMessageNode* intOutMessageNode = FB_NEW_POOL(csbPool) IntMessageNode(tdbb, csbPool, csb, 1,
prc->getOutputFields(), prc->getOutputFormat()); prc->getOutputFields(), prc->getOutputFormat());
mainNode->statements.add(intOutMessageNode); mainNode->statements.add(intOutMessageNode);
ExtMessageNode* extOutMessageNode = FB_NEW_POOL(getPool()) ExtMessageNode(tdbb, getPool(), ExtMessageNode* extOutMessageNode = FB_NEW_POOL(csbPool) ExtMessageNode(tdbb, csbPool,
csb, 3, extOutputFormat); csb, 3, extOutputFormat);
mainNode->statements.add(extOutMessageNode); mainNode->statements.add(extOutMessageNode);
// Initialize the output fields into the external message. // Initialize the output fields into the external message.
InitOutputNode* initOutputNode = FB_NEW_POOL(getPool()) InitOutputNode( InitOutputNode* initOutputNode = FB_NEW_POOL(csbPool) InitOutputNode(
tdbb, getPool(), csb, prc->getOutputFields(), extOutMessageNode); tdbb, csbPool, csb, prc->getOutputFields(), extOutMessageNode);
mainNode->statements.add(initOutputNode); mainNode->statements.add(initOutputNode);
ReceiveNode* receiveNode = intInMessageNode ? ReceiveNode* receiveNode = intInMessageNode ?
FB_NEW_POOL(getPool()) ReceiveNode(getPool()) : NULL; FB_NEW_POOL(csbPool) ReceiveNode(csbPool) : NULL;
if (intInMessageNode) if (intInMessageNode)
{ {
CompoundStmtNode* receiveSubStatement = FB_NEW_POOL(getPool()) CompoundStmtNode(getPool()); CompoundStmtNode* receiveSubStatement = FB_NEW_POOL(csbPool) CompoundStmtNode(csbPool);
receiveSubStatement->statements.add(FB_NEW_POOL(getPool()) MessageMoverNode( receiveSubStatement->statements.add(FB_NEW_POOL(csbPool) MessageMoverNode(
getPool(), intInMessageNode, extInMessageNode)); csbPool, intInMessageNode, extInMessageNode));
receiveSubStatement->statements.add(FB_NEW_POOL(getPool()) StallNode(getPool())); receiveSubStatement->statements.add(FB_NEW_POOL(csbPool) StallNode(csbPool));
receiveNode->statement = receiveSubStatement; receiveNode->statement = receiveSubStatement;
receiveNode->message = intInMessageNode; receiveNode->message = intInMessageNode;
@ -1511,9 +1513,9 @@ void ExtEngineManager::makeProcedure(thread_db* tdbb, CompilerScratch* csb, jrd_
mainNode->statements.add(receiveNode); mainNode->statements.add(receiveNode);
} }
else else
mainNode->statements.add(FB_NEW_POOL(getPool()) StallNode(getPool())); mainNode->statements.add(FB_NEW_POOL(csbPool) StallNode(csbPool));
ExtProcedureNode* extProcedureNode = FB_NEW_POOL(getPool()) ExtProcedureNode(getPool(), ExtProcedureNode* extProcedureNode = FB_NEW_POOL(csbPool) ExtProcedureNode(csbPool,
extInMessageNode, extOutMessageNode, intOutMessageNode, prc->getExternal()); extInMessageNode, extOutMessageNode, intOutMessageNode, prc->getExternal());
mainNode->statements.add(extProcedureNode); mainNode->statements.add(extProcedureNode);
@ -1607,13 +1609,15 @@ void ExtEngineManager::makeTrigger(thread_db* tdbb, CompilerScratch* csb, Jrd::T
try try
{ {
trg->extTrigger = FB_NEW_POOL(getPool()) Trigger(tdbb, pool, csb, this, attInfo->engine, trg->extTrigger = FB_NEW_POOL(pool) Trigger(tdbb, pool, csb, this, attInfo->engine,
metadata.release(), externalTrigger, trg); metadata.release(), externalTrigger, trg);
CompoundStmtNode* mainNode = FB_NEW_POOL(getPool()) CompoundStmtNode(getPool()); MemoryPool& csbPool = csb->csb_pool;
CompoundStmtNode* mainNode = FB_NEW_POOL(csbPool) CompoundStmtNode(csbPool);
mainNode->statements.append(trg->extTrigger->computedStatements); mainNode->statements.append(trg->extTrigger->computedStatements);
ExtTriggerNode* extTriggerNode = FB_NEW_POOL(getPool()) ExtTriggerNode(getPool(), ExtTriggerNode* extTriggerNode = FB_NEW_POOL(csbPool) ExtTriggerNode(csbPool,
trg->extTrigger); trg->extTrigger);
mainNode->statements.add(extTriggerNode); mainNode->statements.add(extTriggerNode);