diff --git a/src/plugins/udr_engine/UdrEngine.cpp b/src/plugins/udr_engine/UdrEngine.cpp index 2b29e8e594a..4f71b025274 100644 --- a/src/plugins/udr_engine/UdrEngine.cpp +++ b/src/plugins/udr_engine/UdrEngine.cpp @@ -100,8 +100,8 @@ class Engine : public StdPlugin SharedObjType* sharedObj, IExternalContext* context, SortedArray& sharedObjs, const PathName& moduleName); - template void deleteChildren( - GenericMap > >& children); + template + void sharedObjectCleanup(SharedObjType* sharedObj, SortedArray& sharedObjs); template T* findNode(ThrowStatusWrapper* status, const GenericMap > >& nodes, const string& entryPoint); @@ -285,7 +285,7 @@ class SharedFunction : public DisposeIfacedeleteChildren(children); + engine->sharedObjectCleanup(this, engine->functions); } public: @@ -347,7 +347,7 @@ class SharedProcedure : public DisposeIfacedeleteChildren(children); + engine->sharedObjectCleanup(this, engine->procedures); } public: @@ -408,7 +408,7 @@ class SharedTrigger : public DisposeIfacedeleteChildren(children); + engine->sharedObjectCleanup(this, engine->triggers); } public: @@ -606,16 +606,17 @@ template ObjType* } -template void Engine::deleteChildren( - GenericMap > >& children) +template +void Engine::sharedObjectCleanup(SharedObjType* sharedObj, SortedArray& sharedObjs) { - // No need to lock childrenMutex as if there are more threads simultaneously accessing - // these children in this moment there will be a memory corruption anyway. + MutexLockGuard guard(childrenMutex, FB_FUNCTION); + + for (auto child : sharedObj->children) + child.second->dispose(); - typedef typename GenericMap > >::Accessor ChildrenAccessor; - ChildrenAccessor accessor(&children); - for (bool found = accessor.getFirst(); found; found = accessor.getNext()) - accessor.current()->second->dispose(); + FB_SIZE_T pos; + if (sharedObjs.find(sharedObj, pos)) + sharedObjs.remove(pos); }