aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSmallJoker <mk939@ymail.com>2021-02-05 18:34:25 +0100
committerSmallJoker <mk939@ymail.com>2021-02-05 18:38:34 +0100
commitd287da184cff737a661a78a2d485b6915316b28b (patch)
treeaaa62f60f949fe023e8f8f831fe6620e3dc2ed2c /src
parent9b64834c6a2ae6eb254e486c87864e6116cfafa1 (diff)
downloadminetest-d287da184cff737a661a78a2d485b6915316b28b.tar.gz
minetest-d287da184cff737a661a78a2d485b6915316b28b.tar.bz2
minetest-d287da184cff737a661a78a2d485b6915316b28b.zip
Server: properly delete ServerMap on interrupted startups
A static mod error (e.g. typo) would abort the initialization but never free ServerMap
Diffstat (limited to 'src')
-rw-r--r--src/map_settings_manager.cpp3
-rw-r--r--src/server.cpp3
-rw-r--r--src/server.h4
3 files changed, 9 insertions, 1 deletions
diff --git a/src/map_settings_manager.cpp b/src/map_settings_manager.cpp
index ed65eed1c..99e3cb0e6 100644
--- a/src/map_settings_manager.cpp
+++ b/src/map_settings_manager.cpp
@@ -116,7 +116,8 @@ bool MapSettingsManager::saveMapMeta()
{
// If mapgen params haven't been created yet; abort
if (!mapgen_params) {
- errorstream << "saveMapMeta: mapgen_params not present!" << std::endl;
+ infostream << "saveMapMeta: mapgen_params not present! "
+ << "Server startup was probably interrupted." << std::endl;
return false;
}
diff --git a/src/server.cpp b/src/server.cpp
index b815558fb..af4eb17e2 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -351,6 +351,7 @@ Server::~Server()
// Deinitialize scripting
infostream << "Server: Deinitializing scripting" << std::endl;
delete m_script;
+ delete m_startup_server_map; // if available
delete m_game_settings;
while (!m_unsent_map_edit_queue.empty()) {
@@ -399,6 +400,7 @@ void Server::init()
// Create the Map (loads map_meta.txt, overriding configured mapgen params)
ServerMap *servermap = new ServerMap(m_path_world, this, m_emerge, m_metrics_backend.get());
+ m_startup_server_map = servermap;
// Initialize scripting
infostream << "Server: Initializing Lua" << std::endl;
@@ -440,6 +442,7 @@ void Server::init()
m_craftdef->initHashes(this);
// Initialize Environment
+ m_startup_server_map = nullptr; // Ownership moved to ServerEnvironment
m_env = new ServerEnvironment(servermap, m_script, this, m_path_world);
m_inventory_mgr->setEnv(m_env);
diff --git a/src/server.h b/src/server.h
index 0b4084aa9..9857215d0 100644
--- a/src/server.h
+++ b/src/server.h
@@ -547,6 +547,10 @@ private:
// Environment
ServerEnvironment *m_env = nullptr;
+ // Reference to the server map until ServerEnvironment is initialized
+ // after that this variable must be a nullptr
+ ServerMap *m_startup_server_map = nullptr;
+
// server connection
std::shared_ptr<con::Connection> m_con;