Changed EventHook name storage to use AString (bug 6188, r=psychonic).

This commit is contained in:
Kyle Sanderson 2014-05-10 02:40:08 -07:00
parent 29ff05bd62
commit f15234e4f8
2 changed files with 5 additions and 9 deletions

View File

@ -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;
}
}

View File

@ -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;
}
};