Fix memleak of multiply chained console commands

This commit is contained in:
heinrich5991 2022-05-04 00:40:12 +02:00
parent 898259fe6c
commit 177cdfdde9

View file

@ -991,8 +991,18 @@ CConsole::~CConsole()
while(pCommand) while(pCommand)
{ {
CCommand *pNext = pCommand->m_pNext; CCommand *pNext = pCommand->m_pNext;
if(pCommand->m_pfnCallback == Con_Chain) {
delete static_cast<CChain *>(pCommand->m_pUserData); FCommandCallback pfnCallback = pCommand->m_pfnCallback;
void *pUserData = pCommand->m_pUserData;
CChain *pChain = nullptr;
while(pfnCallback == Con_Chain)
{
pChain = static_cast<CChain *>(pUserData);
pfnCallback = pChain->m_pfnCallback;
pUserData = pChain->m_pCallbackUserData;
delete pChain;
}
}
// Temp commands are on m_TempCommands heap, so don't delete them // Temp commands are on m_TempCommands heap, so don't delete them
if(!pCommand->m_Temp) if(!pCommand->m_Temp)
delete pCommand; delete pCommand;