1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Settings: Fix unittest memory leak, change input types

This commit is contained in:
SmallJoker 2020-09-22 18:40:34 +02:00
parent 55e2dd911b
commit add68369a5
3 changed files with 15 additions and 15 deletions

View file

@ -822,22 +822,22 @@ bool Settings::setDefault(const std::string &name, const std::string &value)
}
bool Settings::setGroup(const std::string &name, Settings *group)
bool Settings::setGroup(const std::string &name, const Settings &group)
{
// Settings must own the group pointer
// avoid double-free by copying the source
Settings *copy = new Settings();
*copy = *group;
*copy = group;
return setEntry(name, &copy, true, false);
}
bool Settings::setGroupDefault(const std::string &name, Settings *group)
bool Settings::setGroupDefault(const std::string &name, const Settings &group)
{
// Settings must own the group pointer
// avoid double-free by copying the source
Settings *copy = new Settings();
*copy = *group;
*copy = group;
return setEntry(name, &copy, true, true);
}
@ -1060,7 +1060,7 @@ void Settings::overrideDefaults(Settings *other)
{
for (const auto &setting : other->m_settings) {
if (setting.second.is_group) {
setGroupDefault(setting.first, setting.second.group);
setGroupDefault(setting.first, *setting.second.group);
continue;
}
const FlagDesc *flagdesc = getFlagDescFallback(setting.first);