Skip to content

Commit 93b10c3

Browse files
authored
Fix xmlLoadString memory leak (#1531)
Co-authored
1 parent 8e465dc commit 93b10c3

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

Client/mods/deathmatch/logic/lua/CLuaMain.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ CLuaMain::~CLuaMain()
5757

5858
// Delete the timer manager
5959
delete m_pLuaTimerManager;
60+
61+
for (auto& xmlNode : m_XMLNodes)
62+
{
63+
delete xmlNode;
64+
}
6065

6166
CClientPerfStatLuaMemory::GetSingleton()->OnLuaMainDestroy(this);
6267
CClientPerfStatLuaTiming::GetSingleton()->OnLuaMainDestroy(this);
@@ -366,6 +371,8 @@ CXMLFile* CLuaMain::CreateXML(const char* szFilename, bool bUseIDs, bool bReadOn
366371
CXMLNode* CLuaMain::ParseString(const char* strXmlContent)
367372
{
368373
CXMLNode* xmlNode = g_pCore->GetXML()->ParseString(strXmlContent);
374+
if (xmlNode)
375+
m_XMLNodes.push_back(xmlNode);
369376
return xmlNode;
370377
}
371378

Client/mods/deathmatch/logic/lua/CLuaMain.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class CLuaMain //: public CClient
9696
class CResource* m_pResource;
9797

9898
std::list<CXMLFile*> m_XMLFiles;
99+
std::list<CXMLNode*> m_XMLNodes;
99100
static SString ms_strExpectedUndumpHash;
100101

101102
bool m_bEnableOOP;

Server/mods/deathmatch/logic/lua/CLuaMain.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,14 @@ CLuaMain::~CLuaMain()
7272
delete m_pLuaTimerManager;
7373

7474
// Eventually delete the XML files the LUA script didn't
75-
list<CXMLFile*>::iterator iterXML = m_XMLFiles.begin();
76-
for (; iterXML != m_XMLFiles.end(); ++iterXML)
75+
for (auto& xmlFile : m_XMLFiles)
7776
{
78-
delete *iterXML;
77+
delete xmlFile;
78+
}
79+
80+
for (auto& xmlNode : m_XMLNodes)
81+
{
82+
delete xmlNode;
7983
}
8084

8185
// Eventually delete the text displays the LUA script didn't
@@ -419,6 +423,8 @@ CXMLFile* CLuaMain::CreateXML(const char* szFilename, bool bUseIDs, bool bReadOn
419423
CXMLNode* CLuaMain::ParseString(const char* strXmlContent)
420424
{
421425
CXMLNode* xmlNode = g_pServerInterface->GetXML()->ParseString(strXmlContent);
426+
if (xmlNode)
427+
m_XMLNodes.push_back(xmlNode);
422428
return xmlNode;
423429
}
424430

Server/mods/deathmatch/logic/lua/CLuaMain.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ class CLuaMain //: public CClient
134134
CMapManager* m_pMapManager;
135135

136136
list<CXMLFile*> m_XMLFiles;
137+
list<CXMLNode*> m_XMLNodes;
137138
list<CTextDisplay*> m_Displays;
138139
list<CTextItem*> m_TextItems;
139140

0 commit comments

Comments
 (0)