From 12540b96cb64e6fa84d0c7fd2b64864b13a73132 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 27 Aug 2018 19:31:44 +0300 Subject: fixes #1547 (Miranda crashes on import from mmap profile when VK plugin is disabled) --- src/mir_app/src/CMPluginBase.cpp | 4 +--- src/mir_app/src/miranda.h | 16 ++++++++++++++-- src/mir_app/src/newplugins.cpp | 2 ++ src/mir_app/src/proto_accs.cpp | 2 ++ src/mir_app/src/proto_utils.cpp | 2 +- src/mir_app/src/protocols.cpp | 11 +++++------ 6 files changed, 25 insertions(+), 12 deletions(-) (limited to 'src/mir_app') diff --git a/src/mir_app/src/CMPluginBase.cpp b/src/mir_app/src/CMPluginBase.cpp index 4d8a27f48c..2875c00fe1 100644 --- a/src/mir_app/src/CMPluginBase.cpp +++ b/src/mir_app/src/CMPluginBase.cpp @@ -290,9 +290,7 @@ void CMPluginBase::SetUniqueId(const char *pszUniqueId) if (pszUniqueId == nullptr) return; - MBaseProto tmp; - tmp.szName = (char*)m_szModuleName; - MBaseProto *pd = g_arProtos.find(&tmp); + MBaseProto *pd = g_arProtos.find((MBaseProto*)&m_szModuleName); if (pd != nullptr) pd->szUniqueId = mir_strdup(pszUniqueId); } diff --git a/src/mir_app/src/miranda.h b/src/mir_app/src/miranda.h index 23eac6d4ea..bb906d0e35 100644 --- a/src/mir_app/src/miranda.h +++ b/src/mir_app/src/miranda.h @@ -141,8 +141,19 @@ extern MStatus g_statuses[MAX_STATUS_COUNT]; extern LIST accounts; -struct MBaseProto : public PROTOCOLDESCRIPTOR +struct MBaseProto : public PROTOCOLDESCRIPTOR, public MZeroedObject { + MBaseProto(const char *_proto) + { + this->szName = mir_strdup(_proto); + } + + ~MBaseProto() + { + mir_free(szName); + mir_free(szUniqueId); + } + pfnInitProto fnInit; pfnUninitProto fnUninit; @@ -150,7 +161,8 @@ struct MBaseProto : public PROTOCOLDESCRIPTOR char *szUniqueId; // name of the unique setting that identifies a contact }; -extern LIST g_arProtos, g_arFilters; +extern OBJLIST g_arProtos; +extern LIST g_arFilters; INT_PTR ProtoCallService(const char *szModule, const char *szService, WPARAM wParam, LPARAM lParam); diff --git a/src/mir_app/src/newplugins.cpp b/src/mir_app/src/newplugins.cpp index d29a8914e4..ddd630f69a 100644 --- a/src/mir_app/src/newplugins.cpp +++ b/src/mir_app/src/newplugins.cpp @@ -240,6 +240,8 @@ void Plugin_Uninit(pluginEntry *p) HINSTANCE hInst = p->m_pPlugin->getInst(); // we need to kill all resources which belong to that DLL before calling FreeLibrary + KillModuleAccounts(hInst); + KillModuleSubclassing(hInst); KillModuleEventHooks(hInst); KillModuleServices(hInst); diff --git a/src/mir_app/src/proto_accs.cpp b/src/mir_app/src/proto_accs.cpp index 55cbcd8270..8d7f068c9e 100644 --- a/src/mir_app/src/proto_accs.cpp +++ b/src/mir_app/src/proto_accs.cpp @@ -401,6 +401,8 @@ void KillModuleAccounts(HINSTANCE hInst) DeactivateAccount(pa, DAF_DYNAMIC); } } + + g_arProtos.remove(g_arProtos.indexOf(&pd)); } } diff --git a/src/mir_app/src/proto_utils.cpp b/src/mir_app/src/proto_utils.cpp index 4bd1b3da0e..7cbff3bb47 100644 --- a/src/mir_app/src/proto_utils.cpp +++ b/src/mir_app/src/proto_utils.cpp @@ -28,7 +28,7 @@ static int CompareProtos(const MBaseProto *p1, const MBaseProto *p2) return strcmp(p1->szName, p2->szName); } -LIST g_arProtos(10, CompareProtos); +OBJLIST g_arProtos(10, CompareProtos); extern HANDLE hAckEvent; diff --git a/src/mir_app/src/protocols.cpp b/src/mir_app/src/protocols.cpp index f4aea76896..6b6aea19e8 100644 --- a/src/mir_app/src/protocols.cpp +++ b/src/mir_app/src/protocols.cpp @@ -106,8 +106,7 @@ MIR_APP_DLL(PROTOCOLDESCRIPTOR*) Proto_RegisterModule(int type, const char *szNa bool bTryActivate = false; MBaseProto *pd = Proto_GetProto(szName); if (pd == nullptr) { - pd = (MBaseProto*)mir_calloc(sizeof(MBaseProto)); - pd->szName = mir_strdup(szName); + pd = new MBaseProto(szName); g_arProtos.insert(pd); } else bTryActivate = true; @@ -158,17 +157,17 @@ MIR_APP_DLL(const char*) Proto_GetUniqueId(const char *szModuleName) if (szModuleName == nullptr) return nullptr; - MBaseProto tmp; + const char *szProto; PROTOACCOUNT *pa = Proto_GetAccount(szModuleName); if (pa != nullptr) { if (pa->szUniqueId != nullptr) return pa->szUniqueId; - tmp.szName = pa->szProtoName; + szProto = pa->szProtoName; } - else tmp.szName = (char*)szModuleName; + else szProto = szModuleName; - MBaseProto *pd = g_arProtos.find(&tmp); + MBaseProto *pd = g_arProtos.find((MBaseProto*)&szProto); return (pd != nullptr) ? pd->szUniqueId : nullptr; } -- cgit v1.2.3