From 177cdfdde91a8610036e2f51c2738d597b05a93c Mon Sep 17 00:00:00 2001 From: heinrich5991 Date: Wed, 4 May 2022 00:40:12 +0200 Subject: [PATCH] Fix memleak of multiply chained console commands --- src/engine/shared/console.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/engine/shared/console.cpp b/src/engine/shared/console.cpp index 60e1ff62d..255e82fb8 100644 --- a/src/engine/shared/console.cpp +++ b/src/engine/shared/console.cpp @@ -991,8 +991,18 @@ CConsole::~CConsole() while(pCommand) { CCommand *pNext = pCommand->m_pNext; - if(pCommand->m_pfnCallback == Con_Chain) - delete static_cast(pCommand->m_pUserData); + { + FCommandCallback pfnCallback = pCommand->m_pfnCallback; + void *pUserData = pCommand->m_pUserData; + CChain *pChain = nullptr; + while(pfnCallback == Con_Chain) + { + pChain = static_cast(pUserData); + pfnCallback = pChain->m_pfnCallback; + pUserData = pChain->m_pCallbackUserData; + delete pChain; + } + } // Temp commands are on m_TempCommands heap, so don't delete them if(!pCommand->m_Temp) delete pCommand;