Skip to content

Commit

Permalink
Settings: Fix crash on exit due to group double-free
Browse files Browse the repository at this point in the history
  • Loading branch information
SmallJoker committed Sep 21, 2020
1 parent 49117de commit e7f33ee
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/settings.cpp
Expand Up @@ -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);
}


Expand Down

0 comments on commit e7f33ee

Please sign in to comment.