aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSmallJoker <mk939@ymail.com>2020-09-21 19:10:44 +0200
committerSmallJoker <mk939@ymail.com>2020-09-21 19:29:02 +0200
commite7f33ee2f1c57b2b5c48d1a54a5f9e4c72a3275c (patch)
tree99f91f16ef965517e2115991f5aef9b46c85bc4c /src
parent49117de47658cd6c885f88010c9328f8ce3e6e93 (diff)
downloadminetest-e7f33ee2f1c57b2b5c48d1a54a5f9e4c72a3275c.tar.gz
minetest-e7f33ee2f1c57b2b5c48d1a54a5f9e4c72a3275c.tar.bz2
minetest-e7f33ee2f1c57b2b5c48d1a54a5f9e4c72a3275c.zip
Settings: Fix crash on exit due to group double-free
Diffstat (limited to 'src')
-rw-r--r--src/settings.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/settings.cpp b/src/settings.cpp
index 55404319e..473a216bf 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -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);
}