diff --git a/core/EventManager.cpp b/core/EventManager.cpp index 3d40709a..308dbf9c 100644 --- a/core/EventManager.cpp +++ b/core/EventManager.cpp @@ -209,7 +209,7 @@ EventHookError EventManager::HookEvent(const char *name, IPluginFunction *pFunct } /* Cache the name for post hooks */ - pHook->name = sm_strdup(name); + pHook->name = name; /* Increase reference count */ pHook->refCount++; @@ -314,9 +314,6 @@ EventHookError EventManager::UnhookEvent(const char *name, IPluginFunction *pFun /* Delete entry in trie */ m_EventHooks.remove(name); - /* Free the cached name */ - delete pHook->name; - /* And finally free structure memory */ delete pHook; } @@ -477,7 +474,7 @@ bool EventManager::OnFireEvent_Post(IGameEvent *pEvent, bool bDontBroadcast) pForward->PushCell(BAD_HANDLE); } - pForward->PushString(pHook->name); + pForward->PushString(pHook->name.chars()); pForward->PushCell(bDontBroadcast); pForward->Execute(NULL); @@ -498,8 +495,7 @@ bool EventManager::OnFireEvent_Post(IGameEvent *pEvent, bool bDontBroadcast) { assert(pHook->pPostHook == NULL); assert(pHook->pPreHook == NULL); - m_EventHooks.remove(pHook->name); - delete pHook->name; + m_EventHooks.remove(pHook->name.chars()); delete pHook; } } diff --git a/core/EventManager.h b/core/EventManager.h index dc086e63..005b938f 100644 --- a/core/EventManager.h +++ b/core/EventManager.h @@ -69,11 +69,11 @@ struct EventHook IChangeableForward *pPostHook; bool postCopy; unsigned int refCount; - char *name; + ke::AString name; static inline bool matches(const char *name, const EventHook *hook) { - return strcmp(name, hook->name) == 0; + return strcmp(name, hook->name.chars()) == 0; } };