fixed several memory leaks

fixed plugin listeners being removed before a OnPluginUnloaded Call_AskPluginLoad
removed some virtuality
all cached ptrs using the Stack system are freed now

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40647
This commit is contained in:
Borja Ferrer 2007-03-17 00:55:46 +00:00
parent c6166f4b44
commit 6e78ac6302
16 changed files with 135 additions and 81 deletions

View File

@ -56,7 +56,6 @@ void ConCmdManager::OnSourceModShutdown()
/* All commands should already be removed by the time we're done */ /* All commands should already be removed by the time we're done */
SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, SetCommandClient, serverClients, this, &ConCmdManager::SetCommandClient, false); SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, SetCommandClient, serverClients, this, &ConCmdManager::SetCommandClient, false);
g_RootMenu.RemoveRootConsoleCommand("cmds", this); g_RootMenu.RemoveRootConsoleCommand("cmds", this);
g_PluginSys.RemovePluginsListener(this);
} }
void ConCmdManager::RemoveConCmds(List<CmdHook *> &cmdlist, IPluginContext *pContext) void ConCmdManager::RemoveConCmds(List<CmdHook *> &cmdlist, IPluginContext *pContext)

View File

@ -46,6 +46,7 @@ CGameConfig::CGameConfig(const char *file)
m_pProps = sm_trie_create(); m_pProps = sm_trie_create();
m_pKeys = sm_trie_create(); m_pKeys = sm_trie_create();
m_pStrings = new BaseStringTable(512); m_pStrings = new BaseStringTable(512);
m_RefCount = 0;
} }
CGameConfig::~CGameConfig() CGameConfig::~CGameConfig()

View File

@ -27,6 +27,16 @@ void ITimer::Initialize(ITimedEvent *pCallbacks, float fInterval, float fToExec,
m_KillMe = false; m_KillMe = false;
} }
TimerSystem::~TimerSystem()
{
CStack<ITimer *>::iterator iter;
for (iter=m_FreeTimers.begin(); iter!=m_FreeTimers.end(); iter++)
{
delete (*iter);
}
m_FreeTimers.popall();
}
void TimerSystem::OnSourceModAllInitialized() void TimerSystem::OnSourceModAllInitialized()
{ {
g_ShareSys.AddInterface(NULL, this); g_ShareSys.AddInterface(NULL, this);

View File

@ -44,6 +44,8 @@ class TimerSystem :
public ITimerSystem, public ITimerSystem,
public SMGlobalClass public SMGlobalClass
{ {
public:
~TimerSystem();
public: //SMGlobalClass public: //SMGlobalClass
void OnSourceModAllInitialized(); void OnSourceModAllInitialized();
public: //ITimerSystem public: //ITimerSystem

View File

@ -34,6 +34,13 @@ UserMessages::UserMessages() : m_InterceptBuffer(m_pBase, 2500)
UserMessages::~UserMessages() UserMessages::~UserMessages()
{ {
sm_trie_destroy(m_Names); sm_trie_destroy(m_Names);
CStack<ListenerInfo *>::iterator iter;
for (iter=m_FreeListeners.begin(); iter!=m_FreeListeners.end(); iter++)
{
delete (*iter);
}
m_FreeListeners.popall();
} }
void UserMessages::OnSourceModAllInitialized() void UserMessages::OnSourceModAllInitialized()

View File

@ -34,6 +34,8 @@ class TimerNatives :
public IHandleTypeDispatch, public IHandleTypeDispatch,
public ITimedEvent public ITimedEvent
{ {
public:
~TimerNatives();
public: //ITimedEvent public: //ITimedEvent
ResultType OnTimer(ITimer *pTimer, void *pData); ResultType OnTimer(ITimer *pTimer, void *pData);
void OnTimerEnd(ITimer *pTimer, void *pData); void OnTimerEnd(ITimer *pTimer, void *pData);
@ -49,6 +51,16 @@ private:
CStack<TimerInfo *> m_FreeTimers; CStack<TimerInfo *> m_FreeTimers;
}; };
TimerNatives::~TimerNatives()
{
CStack<TimerInfo *>::iterator iter;
for (iter=m_FreeTimers.begin(); iter!=m_FreeTimers.end(); iter++)
{
delete (*iter);
}
m_FreeTimers.popall();
}
void TimerNatives::OnSourceModAllInitialized() void TimerNatives::OnSourceModAllInitialized()
{ {
HandleAccess sec; HandleAccess sec;

View File

@ -34,6 +34,8 @@ class UsrMessageNatives :
public IHandleTypeDispatch, public IHandleTypeDispatch,
public IPluginsListener public IPluginsListener
{ {
public:
~UsrMessageNatives();
public: //SMGlobalClass, IHandleTypeDispatch, IPluginListener public: //SMGlobalClass, IHandleTypeDispatch, IPluginListener
void OnSourceModAllInitialized(); void OnSourceModAllInitialized();
void OnSourceModShutdown(); void OnSourceModShutdown();
@ -47,6 +49,16 @@ private:
CStack<MsgListenerWrapper *> m_FreeListeners; CStack<MsgListenerWrapper *> m_FreeListeners;
}; };
UsrMessageNatives::~UsrMessageNatives()
{
CStack<MsgListenerWrapper *>::iterator iter;
for (iter=m_FreeListeners.begin(); iter!=m_FreeListeners.end(); iter++)
{
delete (*iter);
}
m_FreeListeners.popall();
}
void UsrMessageNatives::OnSourceModAllInitialized() void UsrMessageNatives::OnSourceModAllInitialized()
{ {
HandleAccess sec; HandleAccess sec;
@ -70,7 +82,6 @@ void UsrMessageNatives::OnSourceModShutdown()
g_HandleSys.RemoveType(g_WrBitBufType, g_pCoreIdent); g_HandleSys.RemoveType(g_WrBitBufType, g_pCoreIdent);
g_HandleSys.RemoveType(g_RdBitBufType, g_pCoreIdent); g_HandleSys.RemoveType(g_RdBitBufType, g_pCoreIdent);
g_PluginSys.RemovePluginsListener(this);
g_WrBitBufType = 0; g_WrBitBufType = 0;
g_RdBitBufType = 0; g_RdBitBufType = 0;
} }

View File

@ -264,7 +264,6 @@ void CExtensionManager::OnSourceModAllInitialized()
void CExtensionManager::OnSourceModShutdown() void CExtensionManager::OnSourceModShutdown()
{ {
g_RootMenu.RemoveRootConsoleCommand("exts", this); g_RootMenu.RemoveRootConsoleCommand("exts", this);
g_PluginSys.RemovePluginsListener(this);
g_ShareSys.DestroyIdentType(g_ExtType); g_ShareSys.DestroyIdentType(g_ExtType);
} }

View File

@ -32,17 +32,22 @@ CForwardManager g_Forwards;
// :TODO: IMPORTANT!!! The result pointer arg in the execute function maybe invalid if the forward fails // :TODO: IMPORTANT!!! The result pointer arg in the execute function maybe invalid if the forward fails
// so later evaluation of this result may cause problems on higher levels of abstraction. DOCUMENT OR FIX ALL FORWARDS! // so later evaluation of this result may cause problems on higher levels of abstraction. DOCUMENT OR FIX ALL FORWARDS!
CForwardManager::~CForwardManager()
{
CStack<CForward *>::iterator iter;
for (iter=m_FreeForwards.begin(); iter!=m_FreeForwards.end(); iter++)
{
delete (*iter);
}
m_FreeForwards.popall();
}
void CForwardManager::OnSourceModAllInitialized() void CForwardManager::OnSourceModAllInitialized()
{ {
g_PluginSys.AddPluginsListener(this); g_PluginSys.AddPluginsListener(this);
g_ShareSys.AddInterface(NULL, this); g_ShareSys.AddInterface(NULL, this);
} }
void CForwardManager::OnSourceModShutdown()
{
g_PluginSys.RemovePluginsListener(this);
}
IForward *CForwardManager::CreateForward(const char *name, ExecType et, unsigned int num_params, const ParamType *types, ...) IForward *CForwardManager::CreateForward(const char *name, ExecType et, unsigned int num_params, const ParamType *types, ...)
{ {
CForward *fwd; CForward *fwd;

View File

@ -105,6 +105,8 @@ class CForwardManager :
public SMGlobalClass public SMGlobalClass
{ {
friend class CForward; friend class CForward;
public:
~CForwardManager();
public: //IForwardManager public: //IForwardManager
IForward *CreateForward(const char *name, IForward *CreateForward(const char *name,
ExecType et, ExecType et,
@ -124,7 +126,6 @@ public: //IPluginsListener
void OnPluginPauseChange(IPlugin *plugin, bool paused); void OnPluginPauseChange(IPlugin *plugin, bool paused);
public: //SMGlobalClass public: //SMGlobalClass
void OnSourceModAllInitialized(); void OnSourceModAllInitialized();
void OnSourceModShutdown();
protected: protected:
CForward *ForwardMake(); CForward *ForwardMake();
void ForwardFree(CForward *fwd); void ForwardFree(CForward *fwd);

View File

@ -31,12 +31,12 @@ public:
CDirectory(const char *path); CDirectory(const char *path);
~CDirectory(); ~CDirectory();
public: public:
virtual bool MoreFiles(); bool MoreFiles();
virtual void NextEntry(); void NextEntry();
virtual const char *GetEntryName(); const char *GetEntryName();
virtual bool IsEntryDirectory(); bool IsEntryDirectory();
virtual bool IsEntryFile(); bool IsEntryFile();
virtual bool IsEntryValid(); bool IsEntryValid();
public: public:
bool IsValid(); bool IsValid();
private: private:
@ -56,8 +56,8 @@ public:
CLibrary(LibraryHandle me); CLibrary(LibraryHandle me);
~CLibrary(); ~CLibrary();
public: public:
virtual void CloseLibrary(); void CloseLibrary();
virtual void *GetSymbolAddress(const char *symname); void *GetSymbolAddress(const char *symname);
private: private:
LibraryHandle m_lib; LibraryHandle m_lib;
}; };
@ -65,14 +65,14 @@ private:
class LibrarySystem : public ILibrarySys class LibrarySystem : public ILibrarySys
{ {
public: public:
virtual ILibrary *OpenLibrary(const char *path, char *error, size_t err_max); ILibrary *OpenLibrary(const char *path, char *error, size_t err_max);
virtual IDirectory *OpenDirectory(const char *path); IDirectory *OpenDirectory(const char *path);
virtual void CloseDirectory(IDirectory *dir); void CloseDirectory(IDirectory *dir);
virtual bool PathExists(const char *path); bool PathExists(const char *path);
virtual bool IsPathFile(const char *path); bool IsPathFile(const char *path);
virtual bool IsPathDirectory(const char *path); bool IsPathDirectory(const char *path);
virtual void GetPlatformError(char *error, size_t err_max); void GetPlatformError(char *error, size_t err_max);
virtual size_t PathFormat(char *buffer, size_t len, const char *fmt, ...); size_t PathFormat(char *buffer, size_t len, const char *fmt, ...);
}; };
extern LibrarySystem g_LibSys; extern LibrarySystem g_LibSys;

View File

@ -78,7 +78,7 @@ CPlugin::~CPlugin()
g_pSourcePawn->FreeFromMemory(m_plugin); g_pSourcePawn->FreeFromMemory(m_plugin);
m_plugin = NULL; m_plugin = NULL;
} }
if (!m_pProps) if (m_pProps)
{ {
sm_trie_destroy(m_pProps); sm_trie_destroy(m_pProps);
} }
@ -649,6 +649,13 @@ CPluginManager::~CPluginManager()
*/ */
sm_trie_destroy(m_LoadLookup); sm_trie_destroy(m_LoadLookup);
sm_trie_destroy(m_pNativeLookup); sm_trie_destroy(m_pNativeLookup);
CStack<CPluginManager::CPluginIterator *>::iterator iter;
for (iter=m_iters.begin(); iter!=m_iters.end(); iter++)
{
delete (*iter);
}
m_iters.popall();
} }
void CPluginManager::LoadAll_FirstPass(const char *config, const char *basedir) void CPluginManager::LoadAll_FirstPass(const char *config, const char *basedir)

View File

@ -116,19 +116,19 @@ public:
CPlugin(const char *file); CPlugin(const char *file);
~CPlugin(); ~CPlugin();
public: public:
virtual PluginType GetType(); PluginType GetType();
virtual SourcePawn::IPluginContext *GetBaseContext(); SourcePawn::IPluginContext *GetBaseContext();
virtual sp_context_t *GetContext(); sp_context_t *GetContext();
virtual const sm_plugininfo_t *GetPublicInfo(); const sm_plugininfo_t *GetPublicInfo();
virtual const char *GetFilename(); const char *GetFilename();
virtual bool IsDebugging(); bool IsDebugging();
virtual PluginStatus GetStatus(); PluginStatus GetStatus();
virtual bool SetPauseState(bool paused); bool SetPauseState(bool paused);
virtual unsigned int GetSerial(); unsigned int GetSerial();
virtual const sp_plugin_t *GetPluginStructure(); const sp_plugin_t *GetPluginStructure();
virtual IdentityToken_t *GetIdentity(); IdentityToken_t *GetIdentity();
virtual bool SetProperty(const char *prop, void *ptr); bool SetProperty(const char *prop, void *ptr);
virtual bool GetProperty(const char *prop, void **ptr, bool remove=false); bool GetProperty(const char *prop, void **ptr, bool remove=false);
public: public:
/** /**
* Creates a plugin object with default values. * Creates a plugin object with default values.

View File

@ -36,43 +36,43 @@ namespace SourcePawn
bool IsDebugging(); bool IsDebugging();
int SetDebugBreak(SPVM_DEBUGBREAK newpfn, SPVM_DEBUGBREAK *oldpfn); int SetDebugBreak(SPVM_DEBUGBREAK newpfn, SPVM_DEBUGBREAK *oldpfn);
IPluginDebugInfo *GetDebugInfo(); IPluginDebugInfo *GetDebugInfo();
virtual int HeapAlloc(unsigned int cells, cell_t *local_addr, cell_t **phys_addr); int HeapAlloc(unsigned int cells, cell_t *local_addr, cell_t **phys_addr);
virtual int HeapPop(cell_t local_addr); int HeapPop(cell_t local_addr);
virtual int HeapRelease(cell_t local_addr); int HeapRelease(cell_t local_addr);
virtual int FindNativeByName(const char *name, uint32_t *index); int FindNativeByName(const char *name, uint32_t *index);
virtual int GetNativeByIndex(uint32_t index, sp_native_t **native); int GetNativeByIndex(uint32_t index, sp_native_t **native);
virtual uint32_t GetNativesNum(); uint32_t GetNativesNum();
virtual int FindPublicByName(const char *name, uint32_t *index); int FindPublicByName(const char *name, uint32_t *index);
virtual int GetPublicByIndex(uint32_t index, sp_public_t **publicptr); int GetPublicByIndex(uint32_t index, sp_public_t **publicptr);
virtual uint32_t GetPublicsNum(); uint32_t GetPublicsNum();
virtual int GetPubvarByIndex(uint32_t index, sp_pubvar_t **pubvar); int GetPubvarByIndex(uint32_t index, sp_pubvar_t **pubvar);
virtual int FindPubvarByName(const char *name, uint32_t *index); int FindPubvarByName(const char *name, uint32_t *index);
virtual int GetPubvarAddrs(uint32_t index, cell_t *local_addr, cell_t **phys_addr); int GetPubvarAddrs(uint32_t index, cell_t *local_addr, cell_t **phys_addr);
virtual uint32_t GetPubVarsNum(); uint32_t GetPubVarsNum();
virtual int LocalToPhysAddr(cell_t local_addr, cell_t **phys_addr); int LocalToPhysAddr(cell_t local_addr, cell_t **phys_addr);
virtual int LocalToString(cell_t local_addr, char **addr); int LocalToString(cell_t local_addr, char **addr);
virtual int StringToLocal(cell_t local_addr, size_t chars, const char *source); int StringToLocal(cell_t local_addr, size_t chars, const char *source);
virtual int StringToLocalUTF8(cell_t local_addr, size_t maxbytes, const char *source, size_t *wrtnbytes); int StringToLocalUTF8(cell_t local_addr, size_t maxbytes, const char *source, size_t *wrtnbytes);
virtual int PushCell(cell_t value); int PushCell(cell_t value);
virtual int PushCellArray(cell_t *local_addr, cell_t **phys_addr, cell_t array[], unsigned int numcells); int PushCellArray(cell_t *local_addr, cell_t **phys_addr, cell_t array[], unsigned int numcells);
virtual int PushString(cell_t *local_addr, char **phys_addr, const char *string); int PushString(cell_t *local_addr, char **phys_addr, const char *string);
virtual int PushCellsFromArray(cell_t array[], unsigned int numcells); int PushCellsFromArray(cell_t array[], unsigned int numcells);
virtual int BindNatives(const sp_nativeinfo_t *natives, unsigned int num, int overwrite); int BindNatives(const sp_nativeinfo_t *natives, unsigned int num, int overwrite);
virtual int BindNative(const sp_nativeinfo_t *native); int BindNative(const sp_nativeinfo_t *native);
virtual int BindNativeToAny(SPVM_NATIVE_FUNC native); int BindNativeToAny(SPVM_NATIVE_FUNC native);
virtual int Execute(uint32_t code_addr, cell_t *result); int Execute(uint32_t code_addr, cell_t *result);
virtual cell_t ThrowNativeErrorEx(int error, const char *msg, ...); cell_t ThrowNativeErrorEx(int error, const char *msg, ...);
virtual cell_t ThrowNativeError(const char *msg, ...); cell_t ThrowNativeError(const char *msg, ...);
virtual IPluginFunction *GetFunctionByName(const char *public_name); IPluginFunction *GetFunctionByName(const char *public_name);
virtual IPluginFunction *GetFunctionById(funcid_t func_id); IPluginFunction *GetFunctionById(funcid_t func_id);
#if defined SOURCEMOD_BUILD #if defined SOURCEMOD_BUILD
virtual SourceMod::IdentityToken_t *GetIdentity(); SourceMod::IdentityToken_t *GetIdentity();
void SetIdentity(SourceMod::IdentityToken_t *token); void SetIdentity(SourceMod::IdentityToken_t *token);
#endif #endif
public: //IPluginDebugInfo public: //IPluginDebugInfo
virtual int LookupFile(ucell_t addr, const char **filename); int LookupFile(ucell_t addr, const char **filename);
virtual int LookupFunction(ucell_t addr, const char **name); int LookupFunction(ucell_t addr, const char **name);
virtual int LookupLine(ucell_t addr, uint32_t *line); int LookupLine(ucell_t addr, uint32_t *line);
public: public:
void SetContext(sp_context_t *_ctx); void SetContext(sp_context_t *_ctx);
private: private:

View File

@ -32,13 +32,13 @@ class CContextTrace : public IContextTrace
public: public:
CContextTrace(TracedCall *pStart, int error, const char *msg, uint32_t native); CContextTrace(TracedCall *pStart, int error, const char *msg, uint32_t native);
public: public:
virtual int GetErrorCode(); int GetErrorCode();
virtual const char *GetErrorString(); const char *GetErrorString();
virtual bool DebugInfoAvailable(); bool DebugInfoAvailable();
virtual const char *GetCustomErrorString(); const char *GetCustomErrorString();
virtual bool GetTraceInfo(CallStackInfo *trace); bool GetTraceInfo(CallStackInfo *trace);
virtual void ResetTrace(); void ResetTrace();
virtual const char *GetLastNative(uint32_t *index); const char *GetLastNative(uint32_t *index);
private: private:
int m_Error; int m_Error;
const char *m_pMsg; const char *m_pMsg;
@ -47,7 +47,6 @@ private:
uint32_t m_Native; uint32_t m_Native;
}; };
class SourcePawnEngine : public ISourcePawnEngine class SourcePawnEngine : public ISourcePawnEngine
{ {
public: public:

View File

@ -2259,6 +2259,7 @@ void JITX86::FreeContext(sp_context_t *ctx)
engine->BaseFree(ctx->vm[JITVARS_REBASE]); engine->BaseFree(ctx->vm[JITVARS_REBASE]);
free(((tracker_t *)(ctx->vm[JITVARS_TRACKER]))->pBase); free(((tracker_t *)(ctx->vm[JITVARS_TRACKER]))->pBase);
delete (tracker_t *)ctx->vm[JITVARS_TRACKER]; delete (tracker_t *)ctx->vm[JITVARS_TRACKER];
delete (functracker_t *)ctx->vm[JITVARS_FUNCINFO];
delete ctx; delete ctx;
} }