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

Backport fixes for memory leaks found by Jiří, see "Memory leak with external engine plugin" in fb-devel

This commit is contained in:
hvlad 2021-07-05 16:23:13 +03:00
parent 679ecad8ef
commit f1cb457406

View File

@ -1187,16 +1187,15 @@ void ExtEngineManager::makeFunction(thread_db* tdbb, CompilerScratch* csb, Jrd::
CallerName(obj_udf, udf->getName().identifier) : CallerName(obj_udf, udf->getName().identifier) :
CallerName(obj_package_header, udf->getName().package))); CallerName(obj_package_header, udf->getName().package)));
///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;
metadata->name = udf->getName().identifier; metadata->name = udf->getName().identifier;
metadata->entryPoint = entryPointTrimmed; metadata->entryPoint = entryPointTrimmed;
metadata->body = body; metadata->body = body;
metadata->inputParameters = Routine::createMetadata(udf->getInputFields()); metadata->inputParameters.assignRefNoIncr(Routine::createMetadata(udf->getInputFields()));
metadata->outputParameters = Routine::createMetadata(udf->getOutputFields()); metadata->outputParameters.assignRefNoIncr(Routine::createMetadata(udf->getOutputFields()));
FbLocalStatus status; FbLocalStatus status;
@ -1222,10 +1221,10 @@ void ExtEngineManager::makeFunction(thread_db* tdbb, CompilerScratch* csb, Jrd::
Arg::Gds(isc_eem_func_not_returned) << udf->getName().toString() << engine); Arg::Gds(isc_eem_func_not_returned) << udf->getName().toString() << engine);
} }
extInputParameters = inBuilder->getMetadata(&status); extInputParameters.assignRefNoIncr(inBuilder->getMetadata(&status));
status.check(); status.check();
extOutputParameters = outBuilder->getMetadata(&status); extOutputParameters.assignRefNoIncr(outBuilder->getMetadata(&status));
status.check(); status.check();
} }
@ -1237,13 +1236,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;
@ -1252,38 +1253,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);
@ -1310,16 +1311,15 @@ void ExtEngineManager::makeProcedure(thread_db* tdbb, CompilerScratch* csb, jrd_
CallerName(obj_procedure, prc->getName().identifier) : CallerName(obj_procedure, prc->getName().identifier) :
CallerName(obj_package_header, prc->getName().package))); CallerName(obj_package_header, prc->getName().package)));
///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;
metadata->name = prc->getName().identifier; metadata->name = prc->getName().identifier;
metadata->entryPoint = entryPointTrimmed; metadata->entryPoint = entryPointTrimmed;
metadata->body = body; metadata->body = body;
metadata->inputParameters = Routine::createMetadata(prc->getInputFields()); metadata->inputParameters.assignRefNoIncr(Routine::createMetadata(prc->getInputFields()));
metadata->outputParameters = Routine::createMetadata(prc->getOutputFields()); metadata->outputParameters.assignRefNoIncr(Routine::createMetadata(prc->getOutputFields()));
FbLocalStatus status; FbLocalStatus status;
@ -1346,10 +1346,10 @@ void ExtEngineManager::makeProcedure(thread_db* tdbb, CompilerScratch* csb, jrd_
prc->getName().toString() << engine); prc->getName().toString() << engine);
} }
extInputParameters = inBuilder->getMetadata(&status); extInputParameters.assignRefNoIncr(inBuilder->getMetadata(&status));
status.check(); status.check();
extOutputParameters = outBuilder->getMetadata(&status); extOutputParameters.assignRefNoIncr(outBuilder->getMetadata(&status));
status.check(); status.check();
} }
@ -1361,13 +1361,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;
@ -1376,32 +1378,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;
@ -1409,9 +1411,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);
@ -1439,8 +1441,7 @@ void ExtEngineManager::makeTrigger(thread_db* tdbb, CompilerScratch* csb, Jrd::T
ContextManager<IExternalTrigger> ctxManager(tdbb, attInfo, attInfo->adminCharSet, ContextManager<IExternalTrigger> ctxManager(tdbb, attInfo, attInfo->adminCharSet,
CallerName(obj_trigger, trg->name)); CallerName(obj_trigger, trg->name));
///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->name = trg->name; metadata->name = trg->name;
@ -1501,13 +1502,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);