From 157f050f897aa2865ae2e0993a44444a89aa88aa Mon Sep 17 00:00:00 2001 From: Scott Ehlert Date: Tue, 27 Jan 2009 13:41:57 -0600 Subject: [PATCH 1/3] Fixed a memory leak when game events were hooked as EventHookMode_Post (no bug, r=me). The duplicated event data that was being carried over to the IGameEventManager2::FireEvent post hook was not being freed. EventHookMode_Post is the default so this leak could have happened fairly often. --- core/EventManager.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/EventManager.cpp b/core/EventManager.cpp index d98514f4..0806047f 100644 --- a/core/EventManager.cpp +++ b/core/EventManager.cpp @@ -424,10 +424,11 @@ bool EventManager::OnFireEvent_Post(IGameEvent *pEvent, bool bDontBroadcast) if (sm_trie_retrieve(m_EventHooks, name, reinterpret_cast(&pHook))) { pForward = pHook->pPostHook; + pEventCopy = pHook->pEventCopy; if (pForward) { - EventInfo info = { pHook->pEventCopy, NULL }; + EventInfo info = { pEventCopy, NULL }; if (pHook->postCopy) { From a8e1a4f2fdb7a9471e49e3fd3e4ffba7888e6783 Mon Sep 17 00:00:00 2001 From: TheDOO Date: Mon, 12 Jan 2009 02:33:03 -0500 Subject: [PATCH 2/3] Update of Obsidian CommitSuicide offset (bug 2699, r=dvander). (transplanted from sourcemod-central ffc584a3c382c064006b857e6697c99fff1a681d) --HG-- extra : transplant_source : %FF%C5%84%A3%C3%82%C0d%00k%85%7Ef%97%C9%9F%FF%1Ah%1D --- gamedata/sdktools.games.ep2.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gamedata/sdktools.games.ep2.txt b/gamedata/sdktools.games.ep2.txt index e9a2cbb4..fb7d7993 100644 --- a/gamedata/sdktools.games.ep2.txt +++ b/gamedata/sdktools.games.ep2.txt @@ -582,8 +582,8 @@ } "CommitSuicide" { - "windows" "393" - "linux" "393" + "windows" "395" + "linux" "395" } "GetVelocity" { From 7167a807bff29e3225e92b1124e05a3cae19ada8 Mon Sep 17 00:00:00 2001 From: Scott Ehlert Date: Tue, 27 Jan 2009 23:53:48 -0600 Subject: [PATCH 3/3] Fixed a crash in the Event Manager when a game fired an event from a listener that was looking for the same event (bug 3468, r=me). In other words it was a problem where our FireEvent hooks were being re-entered for the _same_ game event. The Event Manager was not able to handle this and crashed. --- core/EventManager.cpp | 19 +++++++++---------- core/EventManager.h | 9 +++++++-- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/core/EventManager.cpp b/core/EventManager.cpp index 0806047f..6ef124f8 100644 --- a/core/EventManager.cpp +++ b/core/EventManager.cpp @@ -377,21 +377,21 @@ bool EventManager::OnFireEvent(IGameEvent *pEvent, bool bDontBroadcast) if (pForward) { - EventInfo info = { pEvent, NULL }; - + EventInfo info(pEvent, NULL); + HandleSecurity sec(NULL, g_pCoreIdent); Handle_t hndl = g_HandleSys.CreateHandle(m_EventType, &info, NULL, g_pCoreIdent, NULL); + pForward->PushCell(hndl); pForward->PushString(name); pForward->PushCell(bDontBroadcast); pForward->Execute(&res, NULL); - HandleSecurity sec(NULL, g_pCoreIdent); g_HandleSys.FreeHandle(hndl, &sec); } if (pHook->postCopy) { - pHook->pEventCopy = gameevents->DuplicateEvent(pEvent); + m_EventCopies.push(gameevents->DuplicateEvent(pEvent)); } if (res) @@ -407,8 +407,8 @@ bool EventManager::OnFireEvent(IGameEvent *pEvent, bool bDontBroadcast) /* IGameEventManager2::FireEvent post hook */ bool EventManager::OnFireEvent_Post(IGameEvent *pEvent, bool bDontBroadcast) { - IGameEvent *pEventCopy = NULL; EventHook *pHook; + EventInfo info; IChangeableForward *pForward; const char *name; Handle_t hndl = 0; @@ -424,14 +424,13 @@ bool EventManager::OnFireEvent_Post(IGameEvent *pEvent, bool bDontBroadcast) if (sm_trie_retrieve(m_EventHooks, name, reinterpret_cast(&pHook))) { pForward = pHook->pPostHook; - pEventCopy = pHook->pEventCopy; if (pForward) { - EventInfo info = { pEventCopy, NULL }; - if (pHook->postCopy) { + info.pEvent = m_EventCopies.front(); + info.pOwner = NULL; hndl = g_HandleSys.CreateHandle(m_EventType, &info, NULL, g_pCoreIdent, NULL); pForward->PushCell(hndl); @@ -450,8 +449,8 @@ bool EventManager::OnFireEvent_Post(IGameEvent *pEvent, bool bDontBroadcast) g_HandleSys.FreeHandle(hndl, &sec); /* Free event structure */ - gameevents->FreeEvent(pEventCopy); - pHook->pEventCopy = NULL; + gameevents->FreeEvent(info.pEvent); + m_EventCopies.pop(); } } } diff --git a/core/EventManager.h b/core/EventManager.h index 54a830bc..faa8bc45 100644 --- a/core/EventManager.h +++ b/core/EventManager.h @@ -45,6 +45,12 @@ using namespace SourceHook; struct EventInfo { + EventInfo() + { + } + EventInfo(IGameEvent *ev, IdentityToken_t *owner) : pEvent(ev), pOwner(owner) + { + } IGameEvent *pEvent; IdentityToken_t *pOwner; }; @@ -56,13 +62,11 @@ struct EventHook pPreHook = NULL; pPostHook = NULL; postCopy = false; - pEventCopy = NULL; refCount = 0; } IChangeableForward *pPreHook; IChangeableForward *pPostHook; bool postCopy; - IGameEvent *pEventCopy; unsigned int refCount; }; @@ -121,6 +125,7 @@ private: Trie *m_EventHooks; CStack m_FreeEvents; CStack m_EventNames; + CStack m_EventCopies; }; extern EventManager g_EventManager;