From 80ba4766d8ce9861f6d026e791abc741e3fed0f4 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 19 Feb 2017 05:47:59 +0300 Subject: Fix some memory leaks and add duplicate item fields check. --- src/gui/theme.cpp | 55 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 21 deletions(-) (limited to 'src/gui/theme.cpp') diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index 064bec44f..9fa1b59ec 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -1178,16 +1178,28 @@ ImageSet *Theme::getImageSetFromThemeXml(const std::string &name, } #define readValue(name) \ - info->name = reinterpret_cast(\ - XmlNodeGetContent(infoNode)) + { \ + tmpData = reinterpret_cast( \ + XmlNodeGetContent(infoNode)); \ + info->name = tmpData; \ + XmlFree(tmpData); \ + } #define readIntValue(name) \ - info->name = atoi(reinterpret_cast(\ - XmlNodeGetContent(infoNode))) + { \ + tmpData = reinterpret_cast( \ + XmlNodeGetContent(infoNode)); \ + info->name = atoi(tmpData); \ + XmlFree(tmpData); \ + } #define readFloatValue(name) \ - info->name = static_cast(atof(reinterpret_cast(\ - XmlNodeGetContent(infoNode)))) + { \ + tmpData = reinterpret_cast( \ + XmlNodeGetContent(infoNode)); \ + info->name = static_cast(atof(tmpData)); \ + XmlFree(tmpData); \ + } ThemeInfo *Theme::loadInfo(const std::string &themeName) { @@ -1219,38 +1231,39 @@ ThemeInfo *Theme::loadInfo(const std::string &themeName) const std::string fontSize2("fontSize_" + mScreenDensity); const std::string npcfontSize2("npcfontSize_" + mScreenDensity); + char *tmpData = nullptr; for_each_xml_child_node(infoNode, rootNode) { if (xmlNameEqual(infoNode, "name")) - readValue(name); + readValue(name) else if (xmlNameEqual(infoNode, "copyright")) - readValue(copyright); + readValue(copyright) else if (xmlNameEqual(infoNode, "font")) - readValue(font); + readValue(font) else if (xmlNameEqual(infoNode, "boldFont")) - readValue(boldFont); + readValue(boldFont) else if (xmlNameEqual(infoNode, "particleFont")) - readValue(particleFont); + readValue(particleFont) else if (xmlNameEqual(infoNode, "helpFont")) - readValue(helpFont); + readValue(helpFont) else if (xmlNameEqual(infoNode, "secureFont")) - readValue(secureFont); + readValue(secureFont) else if (xmlNameEqual(infoNode, "npcFont")) - readValue(npcFont); + readValue(npcFont) else if (xmlNameEqual(infoNode, "japanFont")) - readValue(japanFont); + readValue(japanFont) else if (xmlNameEqual(infoNode, "chinaFont")) - readValue(chinaFont); + readValue(chinaFont) else if (xmlNameEqual(infoNode, "fontSize")) - readIntValue(fontSize); + readIntValue(fontSize) else if (xmlNameEqual(infoNode, "npcfontSize")) - readIntValue(npcfontSize); + readIntValue(npcfontSize) else if (xmlNameEqual(infoNode, "guialpha")) - readFloatValue(guiAlpha); + readFloatValue(guiAlpha) else if (xmlNameEqual(infoNode, fontSize2.c_str())) - readIntValue(fontSize); + readIntValue(fontSize) else if (xmlNameEqual(infoNode, npcfontSize2.c_str())) - readIntValue(npcfontSize); + readIntValue(npcfontSize) } doc->decRef(); return info; -- cgit v1.2.3-70-g09d2