diff --git a/src/engine/shared/console.cpp b/src/engine/shared/console.cpp index a63f2b253..6cfa920d6 100644 --- a/src/engine/shared/console.cpp +++ b/src/engine/shared/console.cpp @@ -840,6 +840,19 @@ CConsole::CConsole(int FlagMask) m_Cheated = false; } +CConsole::~CConsole() +{ + CCommand *pCommand = m_pFirstCommand; + while(pCommand) + { + CCommand *pNext = pCommand->m_pNext; + if(pCommand->m_pfnCallback == Con_Chain) + mem_free(static_cast(pCommand->m_pUserData)); + delete pCommand; + pCommand = pNext; + } +} + void CConsole::ParseArguments(int NumArgs, const char **ppArguments) { for(int i = 0; i < NumArgs; i++) @@ -895,7 +908,7 @@ void CConsole::Register(const char *pName, const char *pParams, bool DoAdd = false; if(pCommand == 0) { - pCommand = new(mem_alloc(sizeof(CCommand), sizeof(void*))) CCommand; + pCommand = new CCommand(); DoAdd = true; } pCommand->m_pfnCallback = pfnFunc; diff --git a/src/engine/shared/console.h b/src/engine/shared/console.h index d93891b08..457d85c03 100644 --- a/src/engine/shared/console.h +++ b/src/engine/shared/console.h @@ -180,6 +180,7 @@ class CConsole : public IConsole public: CConsole(int FlagMask); + ~CConsole(); virtual const CCommandInfo *FirstCommandInfo(int AccessLevel, int FlagMask) const; virtual const CCommandInfo *GetCommandInfo(const char *pName, int FlagMask, bool Temp);