From 7352a4a4329f0d91f6b69da785891f917d261827 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 27 Mar 2018 16:45:32 +0300 Subject: Core: - fix for chaos with service & hooks owners; - added 'mild' unload option for a plugin not to remove it completely from memory, only correctly deinit it --- src/mir_app/src/modules.cpp | 4 ++++ src/mir_app/src/newplugins.cpp | 25 +++++++++++++++++-------- src/mir_app/src/plugins.h | 2 +- 3 files changed, 22 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/mir_app/src/modules.cpp b/src/mir_app/src/modules.cpp index 2c51f52b04..9f77361280 100644 --- a/src/mir_app/src/modules.cpp +++ b/src/mir_app/src/modules.cpp @@ -146,6 +146,10 @@ int LoadDefaultModules(void) default: // smth went wrong, terminating return 1; } + + for (auto &it : pluginList.rev_iter()) + if (!it->bIsLast && it->bOk) + Plugin_UnloadDyn(it, false); plugin_service = nullptr; } diff --git a/src/mir_app/src/newplugins.cpp b/src/mir_app/src/newplugins.cpp index 21e8c78419..80bc8897c0 100644 --- a/src/mir_app/src/newplugins.cpp +++ b/src/mir_app/src/newplugins.cpp @@ -342,7 +342,7 @@ void Plugin_Uninit(pluginEntry *p) pluginList.remove(p); } -int Plugin_UnloadDyn(pluginEntry *p) +int Plugin_UnloadDyn(pluginEntry *p, bool bFreeDll) { if (p->bpi.hInst) { if (CallPluginEventHook(p->bpi.hInst, hOkToExitEvent, 0, 0) != 0) @@ -374,13 +374,19 @@ int Plugin_UnloadDyn(pluginEntry *p) NotifyFastHook(hevUnloadModule, (WPARAM)p->bpi.pluginInfo, (LPARAM)p->bpi.hInst); - Plugin_Uninit(p); + if (bFreeDll) { + Plugin_Uninit(p); - // mark default plugins to be loaded - if (!p->bIsCore) - for (auto &it : pluginDefault) - if (it.pImpl == p) - it.pImpl = nullptr; + // mark default plugins to be loaded + if (!p->bIsCore) + for (auto &it : pluginDefault) + if (it.pImpl == p) + it.pImpl = nullptr; + } + else if (p->bLoaded) { + p->bpi.Unload(); + p->bLoaded = false; + } return TRUE; } @@ -445,7 +451,7 @@ pluginEntry* OpenPlugin(wchar_t *tszFileName, wchar_t *dir, wchar_t *path) BASIC_PLUGIN_INFO bpi; if (checkAPI(tszFullPath, &bpi, mirandaVersion, CHECKAPI_NONE)) { // plugin is valid - p->bHasBasicApi = true; + p->bHasBasicApi = p->bIsLast = true; if (bIsDb) p->bIsDatabase = true; else @@ -694,6 +700,7 @@ int LaunchServicePlugin(pluginEntry *p) { // plugin load failed - terminating Miranda if (!p->bLoaded) { + RegisterModule(p->bpi.hInst); if (p->bpi.Load() != ERROR_SUCCESS) { Plugin_Uninit(p); return SERVICE_FAILED; @@ -856,6 +863,8 @@ int LoadNewPluginsModuleInfos(void) hPluginListHeap = HeapCreate(HEAP_NO_SERIALIZE, 0, 0); mirandaVersion = Miranda_GetVersion(); + RegisterModule(g_hInst); + // remember where the mirandaboot.ini goes PathToAbsoluteW(L"mirandaboot.ini", mirandabootini); diff --git a/src/mir_app/src/plugins.h b/src/mir_app/src/plugins.h index d860df1a67..9be88a225f 100644 --- a/src/mir_app/src/plugins.h +++ b/src/mir_app/src/plugins.h @@ -74,7 +74,7 @@ pluginEntry* OpenPlugin(wchar_t *tszFileName, wchar_t *dir, wchar_t *path); bool TryLoadPlugin(pluginEntry *p, bool bDynamic); void Plugin_Uninit(pluginEntry *p); -int Plugin_UnloadDyn(pluginEntry *p); +int Plugin_UnloadDyn(pluginEntry *p, bool bFreeDll = true); typedef BOOL (*SCAN_PLUGINS_CALLBACK) (WIN32_FIND_DATA * fd, wchar_t *path, WPARAM wParam, LPARAM lParam); void enumPlugins(SCAN_PLUGINS_CALLBACK cb, WPARAM wParam, LPARAM lParam); -- cgit v1.2.3