From 430e63d6cda596306cd5267466372fe76c79aad5 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 15 Jul 2007 20:27:11 +0000 Subject: [PATCH] fixed crash bug when unloading a plugin with a weak ntvref --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401127 --- core/systems/ExtensionSys.cpp | 29 ++++++++++++++++------------- core/systems/ExtensionSys.h | 2 +- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/core/systems/ExtensionSys.cpp b/core/systems/ExtensionSys.cpp index 35a20379..f60043ed 100644 --- a/core/systems/ExtensionSys.cpp +++ b/core/systems/ExtensionSys.cpp @@ -125,13 +125,6 @@ CExtension::~CExtension() { m_pLib->CloseLibrary(); } - - List::iterator iter; - for (iter=m_WeakNatives.begin(); iter!=m_WeakNatives.end(); iter++) - { - delete (*iter); - } - m_WeakNatives.clear(); } void CExtension::MarkAllLoaded() @@ -156,6 +149,17 @@ void CExtension::AddPlugin(IPlugin *pPlugin) void CExtension::RemovePlugin(IPlugin *pPlugin) { m_Plugins.remove(pPlugin); + + List::iterator iter = m_WeakNatives.begin(); + while (iter != m_WeakNatives.end()) + { + if ((*iter).pl == pPlugin) + { + iter = m_WeakNatives.erase(iter); + } else { + iter++; + } + } } void CExtension::SetError(const char *error) @@ -546,7 +550,7 @@ void CExtensionManager::BindAllNativesToPlugin(IPlugin *pPlugin) { set = true; } else { - WeakNative *wkn = new WeakNative((CPlugin *)pPlugin, idx); + WeakNative wkn = WeakNative((CPlugin *)pPlugin, idx); pExt->m_WeakNatives.push_back(wkn); } } @@ -594,13 +598,12 @@ bool CExtensionManager::UnloadExtension(IExtension *_pExt) } /* Unbound weak natives */ - WeakNative *wkn; - List::iterator wkn_iter; + List::iterator wkn_iter; for (wkn_iter=pExt->m_WeakNatives.begin(); wkn_iter!=pExt->m_WeakNatives.end(); wkn_iter++) { - wkn = (*wkn_iter); - sp_context_t *ctx = wkn->pl->GetContext(); - ctx->natives[wkn->idx].status = SP_NATIVE_UNBOUND; + WeakNative & wkn = (*wkn_iter); + sp_context_t *ctx = wkn.pl->GetContext(); + ctx->natives[wkn.idx].status = SP_NATIVE_UNBOUND; } /* Notify and/or unload all dependencies */ diff --git a/core/systems/ExtensionSys.h b/core/systems/ExtensionSys.h index ed44dcb1..26859faa 100644 --- a/core/systems/ExtensionSys.h +++ b/core/systems/ExtensionSys.h @@ -64,7 +64,7 @@ private: List m_Interfaces; List m_Plugins; List m_Natives; - List m_WeakNatives; + List m_WeakNatives; PluginId m_PlId; unsigned int unload_code; bool m_FullyLoaded;