Skip to content

Fix xmlLoadString memory leak #1531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Client/mods/deathmatch/logic/lua/CLuaMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ CLuaMain::~CLuaMain()

// Delete the timer manager
delete m_pLuaTimerManager;

for (auto& xmlNode : m_XMLNodes)
{
delete xmlNode;
}

CClientPerfStatLuaMemory::GetSingleton()->OnLuaMainDestroy(this);
CClientPerfStatLuaTiming::GetSingleton()->OnLuaMainDestroy(this);
Expand Down Expand Up @@ -366,6 +371,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;
}

Expand Down
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/lua/CLuaMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class CLuaMain //: public CClient
class CResource* m_pResource;

std::list<CXMLFile*> m_XMLFiles;
std::list<CXMLNode*> m_XMLNodes;
static SString ms_strExpectedUndumpHash;

bool m_bEnableOOP;
Expand Down
12 changes: 9 additions & 3 deletions Server/mods/deathmatch/logic/lua/CLuaMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,14 @@ CLuaMain::~CLuaMain()
delete m_pLuaTimerManager;

// Eventually delete the XML files the LUA script didn't
list<CXMLFile*>::iterator iterXML = m_XMLFiles.begin();
for (; iterXML != m_XMLFiles.end(); ++iterXML)
for (auto& xmlFile : m_XMLFiles)
{
delete *iterXML;
delete xmlFile;
}

for (auto& xmlNode : m_XMLNodes)
{
delete xmlNode;
}

// Eventually delete the text displays the LUA script didn't
Expand Down Expand Up @@ -419,6 +423,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;
}

Expand Down
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/lua/CLuaMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class CLuaMain //: public CClient
CMapManager* m_pMapManager;

list<CXMLFile*> m_XMLFiles;
list<CXMLNode*> m_XMLNodes;
list<CTextDisplay*> m_Displays;
list<CTextItem*> m_TextItems;

Expand Down