Initial fixes to ensure static strings passed to new convars
authorScott Ehlert <ds@alliedmods.net>
Sat Feb 17 05:33:31 2007 +0000 (2007-02-17)
changeset 511c29f8796bcf4
parent 510 546acad59370
child 512 44bc3fc6404c
Initial fixes to ensure static strings passed to new convars
Also fixed minor warning in smn_bitbuffer.cpp
core/CConVarManager.cpp
core/smn_bitbuffer.cpp
     1.1 --- a/core/CConVarManager.cpp	Sat Feb 17 04:37:47 2007 +0000
     1.2 +++ b/core/CConVarManager.cpp	Sat Feb 17 05:33:31 2007 +0000
     1.3 @@ -97,7 +97,7 @@
     1.4  void CConVarManager::OnHandleDestroy(HandleType_t type, void *object)
     1.5  {
     1.6  	ConVarInfo *info;
     1.7 -	ConCommandBase *cvar = static_cast<ConCommandBase *>(object);
     1.8 +	ConVar *cvar = static_cast<ConVar *>(object);
     1.9  
    1.10  	// Find convar in lookup trie
    1.11  	sm_trie_retrieve(m_ConVarCache, cvar->GetName(), reinterpret_cast<void **>(&info));
    1.12 @@ -105,6 +105,11 @@
    1.13  	// If convar was created by SourceMod plugin...
    1.14  	if (info->sourceMod)
    1.15  	{
    1.16 +		// Delete string allocations
    1.17 +		delete [] cvar->GetName(); 
    1.18 +		delete [] cvar->GetDefault();
    1.19 +		delete [] cvar->GetHelpText();
    1.20 +
    1.21  		// Then unregister it
    1.22  		g_SMAPI->UnregisterConCmdBase(g_PLAPI, cvar);
    1.23  	}
    1.24 @@ -205,7 +210,7 @@
    1.25  	}
    1.26  
    1.27  	// Since we didn't find an existing convar (or concmd with the same name), now we can finally create it!
    1.28 -	cvar = new ConVar(name, defaultVal, flags, helpText, hasMin, min, hasMax, max);
    1.29 +	cvar = new ConVar(sm_strdup(name), sm_strdup(defaultVal), flags, sm_strdup(helpText), hasMin, min, hasMax, max);
    1.30  
    1.31  	// Find plugin creating convar
    1.32  	IPlugin *pl = g_PluginSys.FindPluginByContext(pContext->GetContext());
     2.1 --- a/core/smn_bitbuffer.cpp	Sat Feb 17 04:37:47 2007 +0000
     2.2 +++ b/core/smn_bitbuffer.cpp	Sat Feb 17 05:33:31 2007 +0000
     2.3 @@ -12,10 +12,10 @@
     2.4  * Version: $Id$
     2.5  */
     2.6  
     2.7 +#include "sourcemod.h"
     2.8 +#include "HandleSys.h"
     2.9  #include <bitbuf.h>
    2.10  #include <vector.h>
    2.11 -#include "sourcemod.h"
    2.12 -#include "HandleSys.h"
    2.13  
    2.14  static cell_t smn_BfWriteBool(IPluginContext *pCtx, const cell_t *params)
    2.15  {