fixed crash bug when unloading a plugin with a weak ntvref
authorDavid Anderson <dvander@alliedmods.net>
Sun Jul 15 20:27:11 2007 +0000 (2007-07-15)
changeset 112192222625d14c
parent 1120 deea3b1a62aa
child 1122 f07d8e10433b
fixed crash bug when unloading a plugin with a weak ntvref
core/systems/ExtensionSys.cpp
core/systems/ExtensionSys.h
     1.1 --- a/core/systems/ExtensionSys.cpp	Sun Jul 15 18:55:13 2007 +0000
     1.2 +++ b/core/systems/ExtensionSys.cpp	Sun Jul 15 20:27:11 2007 +0000
     1.3 @@ -125,13 +125,6 @@
     1.4  	{
     1.5  		m_pLib->CloseLibrary();
     1.6  	}
     1.7 -
     1.8 -	List<WeakNative *>::iterator iter;
     1.9 -	for (iter=m_WeakNatives.begin(); iter!=m_WeakNatives.end(); iter++)
    1.10 -	{
    1.11 -		delete (*iter);
    1.12 -	}
    1.13 -	m_WeakNatives.clear();
    1.14  }
    1.15  
    1.16  void CExtension::MarkAllLoaded()
    1.17 @@ -156,6 +149,17 @@
    1.18  void CExtension::RemovePlugin(IPlugin *pPlugin)
    1.19  {
    1.20  	m_Plugins.remove(pPlugin);
    1.21 +
    1.22 +	List<WeakNative>::iterator iter = m_WeakNatives.begin();
    1.23 +	while (iter != m_WeakNatives.end())
    1.24 +	{
    1.25 +		if ((*iter).pl == pPlugin)
    1.26 +		{
    1.27 +			iter = m_WeakNatives.erase(iter);
    1.28 +		} else {
    1.29 +			iter++;
    1.30 +		}
    1.31 +	}
    1.32  }
    1.33  
    1.34  void CExtension::SetError(const char *error)
    1.35 @@ -546,7 +550,7 @@
    1.36  					{
    1.37  						set = true;
    1.38  					} else {
    1.39 -						WeakNative *wkn = new WeakNative((CPlugin *)pPlugin, idx);
    1.40 +						WeakNative wkn = WeakNative((CPlugin *)pPlugin, idx);
    1.41  						pExt->m_WeakNatives.push_back(wkn);
    1.42  					}
    1.43  				}
    1.44 @@ -594,13 +598,12 @@
    1.45  		}
    1.46  
    1.47  		/* Unbound weak natives */
    1.48 -		WeakNative *wkn;
    1.49 -		List<WeakNative *>::iterator wkn_iter;
    1.50 +		List<WeakNative>::iterator wkn_iter;
    1.51  		for (wkn_iter=pExt->m_WeakNatives.begin(); wkn_iter!=pExt->m_WeakNatives.end(); wkn_iter++)
    1.52  		{
    1.53 -			wkn = (*wkn_iter);
    1.54 -			sp_context_t *ctx = wkn->pl->GetContext();
    1.55 -			ctx->natives[wkn->idx].status = SP_NATIVE_UNBOUND;
    1.56 +			WeakNative & wkn = (*wkn_iter);
    1.57 +			sp_context_t *ctx = wkn.pl->GetContext();
    1.58 +			ctx->natives[wkn.idx].status = SP_NATIVE_UNBOUND;
    1.59  		}
    1.60  
    1.61  		/* Notify and/or unload all dependencies */
     2.1 --- a/core/systems/ExtensionSys.h	Sun Jul 15 18:55:13 2007 +0000
     2.2 +++ b/core/systems/ExtensionSys.h	Sun Jul 15 20:27:11 2007 +0000
     2.3 @@ -64,7 +64,7 @@
     2.4  	List<SMInterface *> m_Interfaces;
     2.5  	List<IPlugin *> m_Plugins;
     2.6  	List<const sp_nativeinfo_t *> m_Natives;
     2.7 -	List<WeakNative *> m_WeakNatives;
     2.8 +	List<WeakNative> m_WeakNatives;
     2.9  	PluginId m_PlId;
    2.10  	unsigned int unload_code;
    2.11  	bool m_FullyLoaded;