]> git.lizzy.rs Git - minetest.git/commitdiff
Settings: Fix crash on exit due to group double-free
authorSmallJoker <mk939@ymail.com>
Mon, 21 Sep 2020 17:10:44 +0000 (19:10 +0200)
committerSmallJoker <mk939@ymail.com>
Mon, 21 Sep 2020 17:29:02 +0000 (19:29 +0200)
src/settings.cpp

index 55404319e8f9615a6f57b2ec5bdb42c9d41f38d6..473a216bf3141852c407682be095353b996f0693 100644 (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);
 }