From 70ef2e4f6658d6337e9d406b1b568b66c78ec1bc Mon Sep 17 00:00:00 2001 From: LopSided <40902730+Lpsd@users.noreply.github.com> Date: Sat, 20 Jun 2020 03:05:15 +0100 Subject: [PATCH 1/2] Destroy XML nodes in CLuaMain destructor --- Client/mods/deathmatch/logic/lua/CLuaMain.cpp | 8 ++++++++ Client/mods/deathmatch/logic/lua/CLuaMain.h | 1 + Server/mods/deathmatch/logic/lua/CLuaMain.cpp | 14 +++++++++++--- Server/mods/deathmatch/logic/lua/CLuaMain.h | 1 + 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Client/mods/deathmatch/logic/lua/CLuaMain.cpp b/Client/mods/deathmatch/logic/lua/CLuaMain.cpp index 53f16c0f661..33aee367313 100644 --- a/Client/mods/deathmatch/logic/lua/CLuaMain.cpp +++ b/Client/mods/deathmatch/logic/lua/CLuaMain.cpp @@ -58,6 +58,12 @@ CLuaMain::~CLuaMain() // Delete the timer manager delete m_pLuaTimerManager; + list::iterator iterXMLNodes = m_XMLNodes.begin(); + for (; iterXMLNodes != m_XMLNodes.end(); ++iterXMLNodes) + { + delete *iterXMLNodes; + } + CClientPerfStatLuaMemory::GetSingleton()->OnLuaMainDestroy(this); CClientPerfStatLuaTiming::GetSingleton()->OnLuaMainDestroy(this); } @@ -366,6 +372,8 @@ CXMLFile* CLuaMain::CreateXML(const char* szFilename, bool bUseIDs, bool bReadOn CXMLNode* CLuaMain::ParseString(const char* strXmlContent) { CXMLNode* xmlNode = g_pCore->GetXML()->ParseString(strXmlContent); + if (xmlNode) + m_XMLNodes.push_back(xmlNode); return xmlNode; } diff --git a/Client/mods/deathmatch/logic/lua/CLuaMain.h b/Client/mods/deathmatch/logic/lua/CLuaMain.h index fb7eb6103c6..387311dcaf8 100644 --- a/Client/mods/deathmatch/logic/lua/CLuaMain.h +++ b/Client/mods/deathmatch/logic/lua/CLuaMain.h @@ -96,6 +96,7 @@ class CLuaMain //: public CClient class CResource* m_pResource; std::list m_XMLFiles; + std::list m_XMLNodes; static SString ms_strExpectedUndumpHash; bool m_bEnableOOP; diff --git a/Server/mods/deathmatch/logic/lua/CLuaMain.cpp b/Server/mods/deathmatch/logic/lua/CLuaMain.cpp index be691f618a8..0272ae00b20 100644 --- a/Server/mods/deathmatch/logic/lua/CLuaMain.cpp +++ b/Server/mods/deathmatch/logic/lua/CLuaMain.cpp @@ -72,10 +72,16 @@ CLuaMain::~CLuaMain() delete m_pLuaTimerManager; // Eventually delete the XML files the LUA script didn't - list::iterator iterXML = m_XMLFiles.begin(); - for (; iterXML != m_XMLFiles.end(); ++iterXML) + list::iterator iterXMLFiles = m_XMLFiles.begin(); + for (; iterXMLFiles != m_XMLFiles.end(); ++iterXMLFiles) { - delete *iterXML; + delete *iterXMLFiles; + } + + list::iterator iterXMLNodes = m_XMLNodes.begin(); + for (; iterXMLNodes != m_XMLNodes.end(); ++iterXMLNodes) + { + delete *iterXMLNodes; } // Eventually delete the text displays the LUA script didn't @@ -419,6 +425,8 @@ CXMLFile* CLuaMain::CreateXML(const char* szFilename, bool bUseIDs, bool bReadOn CXMLNode* CLuaMain::ParseString(const char* strXmlContent) { CXMLNode* xmlNode = g_pServerInterface->GetXML()->ParseString(strXmlContent); + if (xmlNode) + m_XMLNodes.push_back(xmlNode); return xmlNode; } diff --git a/Server/mods/deathmatch/logic/lua/CLuaMain.h b/Server/mods/deathmatch/logic/lua/CLuaMain.h index 47bb8c4ca1d..c54ac8303a4 100644 --- a/Server/mods/deathmatch/logic/lua/CLuaMain.h +++ b/Server/mods/deathmatch/logic/lua/CLuaMain.h @@ -134,6 +134,7 @@ class CLuaMain //: public CClient CMapManager* m_pMapManager; list m_XMLFiles; + list m_XMLNodes; list m_Displays; list m_TextItems; From 2b13b093b7e9085fb7b14961cc16baebf1b780d4 Mon Sep 17 00:00:00 2001 From: LopSided <40902730+Lpsd@users.noreply.github.com> Date: Sat, 20 Jun 2020 16:20:06 +0100 Subject: [PATCH 2/2] Prettify CLuaMain destructor iteration --- Client/mods/deathmatch/logic/lua/CLuaMain.cpp | 7 +++---- Server/mods/deathmatch/logic/lua/CLuaMain.cpp | 10 ++++------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/Client/mods/deathmatch/logic/lua/CLuaMain.cpp b/Client/mods/deathmatch/logic/lua/CLuaMain.cpp index 33aee367313..02131133d72 100644 --- a/Client/mods/deathmatch/logic/lua/CLuaMain.cpp +++ b/Client/mods/deathmatch/logic/lua/CLuaMain.cpp @@ -57,11 +57,10 @@ CLuaMain::~CLuaMain() // Delete the timer manager delete m_pLuaTimerManager; - - list::iterator iterXMLNodes = m_XMLNodes.begin(); - for (; iterXMLNodes != m_XMLNodes.end(); ++iterXMLNodes) + + for (auto& xmlNode : m_XMLNodes) { - delete *iterXMLNodes; + delete xmlNode; } CClientPerfStatLuaMemory::GetSingleton()->OnLuaMainDestroy(this); diff --git a/Server/mods/deathmatch/logic/lua/CLuaMain.cpp b/Server/mods/deathmatch/logic/lua/CLuaMain.cpp index 0272ae00b20..398023601e0 100644 --- a/Server/mods/deathmatch/logic/lua/CLuaMain.cpp +++ b/Server/mods/deathmatch/logic/lua/CLuaMain.cpp @@ -72,16 +72,14 @@ CLuaMain::~CLuaMain() delete m_pLuaTimerManager; // Eventually delete the XML files the LUA script didn't - list::iterator iterXMLFiles = m_XMLFiles.begin(); - for (; iterXMLFiles != m_XMLFiles.end(); ++iterXMLFiles) + for (auto& xmlFile : m_XMLFiles) { - delete *iterXMLFiles; + delete xmlFile; } - list::iterator iterXMLNodes = m_XMLNodes.begin(); - for (; iterXMLNodes != m_XMLNodes.end(); ++iterXMLNodes) + for (auto& xmlNode : m_XMLNodes) { - delete *iterXMLNodes; + delete xmlNode; } // Eventually delete the text displays the LUA script didn't