fixed memory leak in console

This commit is contained in:
HMH 2017-07-21 15:19:44 +02:00
parent b8e997f99e
commit 80fac31175
2 changed files with 15 additions and 1 deletions

View file

@ -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<CChain *>(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;

View file

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