Skip to content

Commit

Permalink
Fixed #7510: Firebird regularly crashes soon after unload of udr_engi…
Browse files Browse the repository at this point in the history
…ne plugin

(cherry picked from commit aed9464)
  • Loading branch information
AlexPeshkoff committed Mar 27, 2023
1 parent c237896 commit 2364801
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 36 deletions.
35 changes: 20 additions & 15 deletions src/jrd/ExtEngineManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,15 +712,26 @@ void* ExtEngineManager::ExternalContextImpl::setInfo(int code, void* value)
//---------------------


ExtEngineManager::Function::Function(thread_db* tdbb, ExtEngineManager* aExtManager,
IExternalEngine* aEngine, RoutineMetadata* aMetadata, IExternalFunction* aFunction,
const Jrd::Function* aUdf)
ExtEngineManager::ExtRoutine::ExtRoutine(thread_db* tdbb, ExtEngineManager* aExtManager,
IExternalEngine* aEngine, RoutineMetadata* aMetadata)
: extManager(aExtManager),
engine(aEngine),
metadata(aMetadata),
function(aFunction),
udf(aUdf),
database(tdbb->getDatabase())
{
engine->addRef();
}


//---------------------


ExtEngineManager::Function::Function(thread_db* tdbb, ExtEngineManager* aExtManager,
IExternalEngine* aEngine, RoutineMetadata* aMetadata, IExternalFunction* aFunction,
const Jrd::Function* aUdf)
: ExtRoutine(tdbb, aExtManager, aEngine, aMetadata),
function(aFunction),
udf(aUdf)
{
}

Expand Down Expand Up @@ -755,12 +766,9 @@ void ExtEngineManager::Function::execute(thread_db* tdbb, UCHAR* inMsg, UCHAR* o
ExtEngineManager::Procedure::Procedure(thread_db* tdbb, ExtEngineManager* aExtManager,
IExternalEngine* aEngine, RoutineMetadata* aMetadata, IExternalProcedure* aProcedure,
const jrd_prc* aPrc)
: extManager(aExtManager),
engine(aEngine),
metadata(aMetadata),
: ExtRoutine(tdbb, aExtManager, aEngine, aMetadata),
procedure(aProcedure),
prc(aPrc),
database(tdbb->getDatabase())
prc(aPrc)
{
}

Expand Down Expand Up @@ -845,15 +853,12 @@ bool ExtEngineManager::ResultSet::fetch(thread_db* tdbb)
ExtEngineManager::Trigger::Trigger(thread_db* tdbb, MemoryPool& pool, CompilerScratch* csb,
ExtEngineManager* aExtManager, IExternalEngine* aEngine, RoutineMetadata* aMetadata,
IExternalTrigger* aTrigger, const Jrd::Trigger* aTrg)
: computedStatements(pool),
extManager(aExtManager),
engine(aEngine),
metadata(aMetadata),
: ExtRoutine(tdbb, aExtManager, aEngine, aMetadata),
computedStatements(pool),
trigger(aTrigger),
trg(aTrg),
fieldsPos(pool),
varDecls(pool),
database(tdbb->getDatabase()),
computedCount(0)
{
jrd_rel* relation = trg->relation;
Expand Down
32 changes: 17 additions & 15 deletions src/jrd/ExtEngineManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "../common/classes/rwlock.h"
#include "../common/classes/ImplementHelper.h"
#include "../common/StatementMetadata.h"
#include "../common/classes/GetPlugins.h"

struct dsc;

Expand Down Expand Up @@ -209,7 +210,20 @@ class ExtEngineManager final : public Firebird::PermanentStorage
};

public:
class Function
class ExtRoutine
{
public:
ExtRoutine(thread_db* tdbb, ExtEngineManager* aExtManager,
Firebird::IExternalEngine* aEngine, RoutineMetadata* aMetadata);

protected:
ExtEngineManager* extManager;
Firebird::AutoPlugin<Firebird::IExternalEngine> engine;
Firebird::AutoPtr<RoutineMetadata> metadata;
Database* database;
};

class Function : public ExtRoutine
{
public:
Function(thread_db* tdbb, ExtEngineManager* aExtManager,
Expand All @@ -222,17 +236,13 @@ class ExtEngineManager final : public Firebird::PermanentStorage
void execute(thread_db* tdbb, UCHAR* inMsg, UCHAR* outMsg) const;

private:
ExtEngineManager* extManager;
Firebird::IExternalEngine* engine;
Firebird::AutoPtr<RoutineMetadata> metadata;
Firebird::IExternalFunction* function;
const Jrd::Function* udf;
Database* database;
};

class ResultSet;

class Procedure
class Procedure : public ExtRoutine
{
public:
Procedure(thread_db* tdbb, ExtEngineManager* aExtManager,
Expand All @@ -245,12 +255,8 @@ class ExtEngineManager final : public Firebird::PermanentStorage
ResultSet* open(thread_db* tdbb, UCHAR* inMsg, UCHAR* outMsg) const;

private:
ExtEngineManager* extManager;
Firebird::IExternalEngine* engine;
Firebird::AutoPtr<RoutineMetadata> metadata;
Firebird::IExternalProcedure* procedure;
const jrd_prc* prc;
Database* database;

friend class ResultSet;
};
Expand All @@ -272,7 +278,7 @@ class ExtEngineManager final : public Firebird::PermanentStorage
USHORT charSet;
};

class Trigger
class Trigger : public ExtRoutine
{
public:
Trigger(thread_db* tdbb, MemoryPool& pool, CompilerScratch* csb, ExtEngineManager* aExtManager,
Expand All @@ -291,15 +297,11 @@ class ExtEngineManager final : public Firebird::PermanentStorage
Firebird::Array<NestConst<StmtNode>> computedStatements;

private:
ExtEngineManager* extManager;
Firebird::IExternalEngine* engine;
Firebird::AutoPtr<RoutineMetadata> metadata;
Firebird::AutoPtr<Format> format;
Firebird::IExternalTrigger* trigger;
const Jrd::Trigger* trg;
Firebird::Array<USHORT> fieldsPos;
Firebird::Array<const DeclareVariableNode*> varDecls;
Database* database;
USHORT computedCount;
};

Expand Down
9 changes: 3 additions & 6 deletions src/plugins/udr_engine/UdrEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ class SharedFunction : public DisposeIface<IExternalFunctionImpl<SharedFunction,
info(*getDefaultMemoryPool()),
children(*getDefaultMemoryPool())
{
engine->addRef();
module = engine->loadModule(status, metadata, &moduleName, &entryPoint);

IUdrFunctionFactory* factory = engine->findNode<IUdrFunctionFactory>(
Expand Down Expand Up @@ -312,7 +311,7 @@ class SharedFunction : public DisposeIface<IExternalFunctionImpl<SharedFunction,
}

public:
AutoPlugin<Engine> engine;
Engine* engine;
IRoutineMetadata* metadata;
PathName moduleName;
string entryPoint;
Expand All @@ -338,7 +337,6 @@ class SharedProcedure : public DisposeIface<IExternalProcedureImpl<SharedProcedu
info(*getDefaultMemoryPool()),
children(*getDefaultMemoryPool())
{
engine->addRef();
module = engine->loadModule(status, metadata, &moduleName, &entryPoint);

IUdrProcedureFactory* factory = engine->findNode<IUdrProcedureFactory>(
Expand Down Expand Up @@ -375,7 +373,7 @@ class SharedProcedure : public DisposeIface<IExternalProcedureImpl<SharedProcedu
}

public:
AutoPlugin<Engine> engine;
Engine* engine;
IRoutineMetadata* metadata;
PathName moduleName;
string entryPoint;
Expand All @@ -400,7 +398,6 @@ class SharedTrigger : public DisposeIface<IExternalTriggerImpl<SharedTrigger, Th
info(*getDefaultMemoryPool()),
children(*getDefaultMemoryPool())
{
engine->addRef();
module = engine->loadModule(status, metadata, &moduleName, &entryPoint);

IUdrTriggerFactory* factory = engine->findNode<IUdrTriggerFactory>(
Expand Down Expand Up @@ -438,7 +435,7 @@ class SharedTrigger : public DisposeIface<IExternalTriggerImpl<SharedTrigger, Th
}

public:
AutoPlugin<Engine> engine;
Engine* engine;
IRoutineMetadata* metadata;
PathName moduleName;
string entryPoint;
Expand Down

0 comments on commit 2364801

Please sign in to comment.