8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 14:03:07 +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 (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_package_header, udf->getName().package, userName)));
///MemoryPool& pool = *tdbb->getDefaultPool();
MemoryPool& pool = *getDefaultMemoryPool();
MemoryPool& pool = *tdbb->getAttachment()->att_pool;
AutoPtr<RoutineMetadata> metadata(FB_NEW_POOL(pool) RoutineMetadata(pool));
metadata->package = udf->getName().package;
@ -1338,13 +1337,15 @@ void ExtEngineManager::makeFunction(thread_db* tdbb, CompilerScratch* csb, Jrd::
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);
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() ?
FB_NEW_POOL(getPool()) IntMessageNode(tdbb, getPool(), csb, 0,
FB_NEW_POOL(csbPool) IntMessageNode(tdbb, csbPool, csb, 0,
udf->getInputFields(), udf->getInputFormat()) :
NULL;
ExtMessageNode* extInMessageNode = NULL;
@ -1353,38 +1354,38 @@ void ExtEngineManager::makeFunction(thread_db* tdbb, CompilerScratch* csb, Jrd::
{
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);
}
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());
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);
mainNode->statements.add(extOutMessageNode);
// Initialize the output fields into the external message.
InitOutputNode* initOutputNode = FB_NEW_POOL(getPool()) InitOutputNode(
tdbb, getPool(), csb, udf->getOutputFields(), extOutMessageNode);
InitOutputNode* initOutputNode = FB_NEW_POOL(csbPool) InitOutputNode(
tdbb, csbPool, csb, udf->getOutputFields(), extOutMessageNode);
mainNode->statements.add(initOutputNode);
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->statement = FB_NEW_POOL(getPool()) MessageMoverNode(
getPool(), intInMessageNode, extInMessageNode);
receiveNode->statement = FB_NEW_POOL(csbPool) MessageMoverNode(
csbPool, intInMessageNode, extInMessageNode);
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);
mainNode->statements.add(extFunctionNode);
extFunctionNode->message = intOutMessageNode;
extFunctionNode->statement = FB_NEW_POOL(getPool()) MessageMoverNode(
getPool(), extOutMessageNode, intOutMessageNode);
extFunctionNode->statement = FB_NEW_POOL(csbPool) MessageMoverNode(
csbPool, extOutMessageNode, intOutMessageNode);
JrdStatement* statement = udf->getStatement();
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_package_header, prc->getName().package, userName)));
///MemoryPool& pool = *tdbb->getDefaultPool();
MemoryPool& pool = *getDefaultMemoryPool();
MemoryPool& pool = *tdbb->getAttachment()->att_pool;
AutoPtr<RoutineMetadata> metadata(FB_NEW_POOL(pool) RoutineMetadata(pool));
metadata->package = prc->getName().package;
@ -1463,13 +1463,15 @@ void ExtEngineManager::makeProcedure(thread_db* tdbb, CompilerScratch* csb, jrd_
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));
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() ?
FB_NEW_POOL(getPool()) IntMessageNode(tdbb, getPool(), csb, 0,
FB_NEW_POOL(csbPool) IntMessageNode(tdbb, csbPool, csb, 0,
prc->getInputFields(), prc->getInputFormat()) :
NULL;
ExtMessageNode* extInMessageNode = NULL;
@ -1478,32 +1480,32 @@ void ExtEngineManager::makeProcedure(thread_db* tdbb, CompilerScratch* csb, jrd_
{
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);
}
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());
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);
mainNode->statements.add(extOutMessageNode);
// Initialize the output fields into the external message.
InitOutputNode* initOutputNode = FB_NEW_POOL(getPool()) InitOutputNode(
tdbb, getPool(), csb, prc->getOutputFields(), extOutMessageNode);
InitOutputNode* initOutputNode = FB_NEW_POOL(csbPool) InitOutputNode(
tdbb, csbPool, csb, prc->getOutputFields(), extOutMessageNode);
mainNode->statements.add(initOutputNode);
ReceiveNode* receiveNode = intInMessageNode ?
FB_NEW_POOL(getPool()) ReceiveNode(getPool()) : NULL;
FB_NEW_POOL(csbPool) ReceiveNode(csbPool) : NULL;
if (intInMessageNode)
{
CompoundStmtNode* receiveSubStatement = FB_NEW_POOL(getPool()) CompoundStmtNode(getPool());
receiveSubStatement->statements.add(FB_NEW_POOL(getPool()) MessageMoverNode(
getPool(), intInMessageNode, extInMessageNode));
receiveSubStatement->statements.add(FB_NEW_POOL(getPool()) StallNode(getPool()));
CompoundStmtNode* receiveSubStatement = FB_NEW_POOL(csbPool) CompoundStmtNode(csbPool);
receiveSubStatement->statements.add(FB_NEW_POOL(csbPool) MessageMoverNode(
csbPool, intInMessageNode, extInMessageNode));
receiveSubStatement->statements.add(FB_NEW_POOL(csbPool) StallNode(csbPool));
receiveNode->statement = receiveSubStatement;
receiveNode->message = intInMessageNode;
@ -1511,9 +1513,9 @@ void ExtEngineManager::makeProcedure(thread_db* tdbb, CompilerScratch* csb, jrd_
mainNode->statements.add(receiveNode);
}
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());
mainNode->statements.add(extProcedureNode);
@ -1607,13 +1609,15 @@ void ExtEngineManager::makeTrigger(thread_db* tdbb, CompilerScratch* csb, Jrd::T
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);
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);
ExtTriggerNode* extTriggerNode = FB_NEW_POOL(getPool()) ExtTriggerNode(getPool(),
ExtTriggerNode* extTriggerNode = FB_NEW_POOL(csbPool) ExtTriggerNode(csbPool,
trg->extTrigger);
mainNode->statements.add(extTriggerNode);