summaryrefslogtreecommitdiff
path: root/src/gui/theme.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-02-19 05:47:59 +0300
committerAndrei Karas <akaras@inbox.ru>2017-02-19 23:04:53 +0300
commit80ba4766d8ce9861f6d026e791abc741e3fed0f4 (patch)
tree02d509ecd3ae384fba0b8d44a60c71033e3d31d3 /src/gui/theme.cpp
parent4526407e2001244a03674e57db8a6807cbbbe2b0 (diff)
downloadmv-80ba4766d8ce9861f6d026e791abc741e3fed0f4.tar.gz
mv-80ba4766d8ce9861f6d026e791abc741e3fed0f4.tar.bz2
mv-80ba4766d8ce9861f6d026e791abc741e3fed0f4.tar.xz
mv-80ba4766d8ce9861f6d026e791abc741e3fed0f4.zip
Fix some memory leaks and add duplicate item fields check.
Diffstat (limited to 'src/gui/theme.cpp')
-rw-r--r--src/gui/theme.cpp55
1 files changed, 34 insertions, 21 deletions
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<const char*>(\
- XmlNodeGetContent(infoNode))
+ { \
+ tmpData = reinterpret_cast<char*>( \
+ XmlNodeGetContent(infoNode)); \
+ info->name = tmpData; \
+ XmlFree(tmpData); \
+ }
#define readIntValue(name) \
- info->name = atoi(reinterpret_cast<const char*>(\
- XmlNodeGetContent(infoNode)))
+ { \
+ tmpData = reinterpret_cast<char*>( \
+ XmlNodeGetContent(infoNode)); \
+ info->name = atoi(tmpData); \
+ XmlFree(tmpData); \
+ }
#define readFloatValue(name) \
- info->name = static_cast<float>(atof(reinterpret_cast<const char*>(\
- XmlNodeGetContent(infoNode))))
+ { \
+ tmpData = reinterpret_cast<char*>( \
+ XmlNodeGetContent(infoNode)); \
+ info->name = static_cast<float>(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;