Settings: Fix crash on exit due to group double-free

master
SmallJoker 2020-09-21 19:10:44 +02:00
parent 49117de476
commit e7f33ee2f1
1 changed files with 10 additions and 2 deletions

View File

@ -824,13 +824,21 @@ bool Settings::setDefault(const std::string &name, const std::string &value)
bool Settings::setGroup(const std::string &name, Settings *group)
{
return setEntry(name, &group, true, false);
// Settings must own the group pointer
// avoid double-free by copying the source
Settings *copy = new Settings();
*copy = *group;
return setEntry(name, &copy, true, false);
}
bool Settings::setGroupDefault(const std::string &name, Settings *group)
{
return setEntry(name, &group, true, true);
// Settings must own the group pointer
// avoid double-free by copying the source
Settings *copy = new Settings();
*copy = *group;
return setEntry(name, &copy, true, true);
}