mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-21 14:50:06 +02:00
Loaded modules managed by smart pointers
This commit is contained in:
parent
e0476b5e71
commit
29349fedbb
@ -449,7 +449,7 @@ void ModuleManager::InitializeBuiltins()
|
||||
|
||||
ModuleInterface *ModuleManager::LoadModule(const wxString & path)
|
||||
{
|
||||
wxDynamicLibrary *lib = new wxDynamicLibrary();
|
||||
auto lib = std::make_unique<wxDynamicLibrary>();
|
||||
|
||||
if (lib->Load(path, wxDL_NOW))
|
||||
{
|
||||
@ -468,7 +468,7 @@ ModuleInterface *ModuleManager::LoadModule(const wxString & path)
|
||||
|
||||
auto module = handle.get();
|
||||
mDynModules[PluginManager::GetID(module)] = std::move(handle);
|
||||
mLibs[module] = lib;
|
||||
mLibs[module] = std::move(lib);
|
||||
|
||||
return module;
|
||||
}
|
||||
@ -478,8 +478,6 @@ ModuleInterface *ModuleManager::LoadModule(const wxString & path)
|
||||
lib->Unload();
|
||||
}
|
||||
|
||||
delete lib;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -490,11 +488,10 @@ void ModuleInterfaceDeleter::operator() (ModuleInterface *pInterface) const
|
||||
pInterface->Terminate();
|
||||
|
||||
auto &libs = ModuleManager::Get().mLibs;
|
||||
if (libs.find(pInterface) != libs.end())
|
||||
{
|
||||
libs[pInterface]->Unload();
|
||||
libs.erase(pInterface);
|
||||
}
|
||||
|
||||
auto iter = libs.find(pInterface);
|
||||
if (iter != libs.end())
|
||||
libs.erase(iter); // This causes unloading in ~wxDynamicLibrary
|
||||
|
||||
delete pInterface;
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ using ModuleInterfaceHandle = movable_ptr_with_deleter<
|
||||
|
||||
typedef std::map<wxString, ModuleMain *> ModuleMainMap;
|
||||
typedef std::map<wxString, ModuleInterfaceHandle> ModuleMap;
|
||||
typedef std::map<ModuleInterface *, wxDynamicLibrary *> LibraryMap;
|
||||
typedef std::map<ModuleInterface *, movable_ptr<wxDynamicLibrary>> LibraryMap;
|
||||
|
||||
class ModuleManager final : public ModuleManagerInterface
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user