Skip to content

Commit d287da1

Browse files
committedFeb 5, 2021
Server: properly delete ServerMap on interrupted startups
A static mod error (e.g. typo) would abort the initialization but never free ServerMap
1 parent 9b64834 commit d287da1

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed
 

‎src/map_settings_manager.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ bool MapSettingsManager::saveMapMeta()
116116
{
117117
// If mapgen params haven't been created yet; abort
118118
if (!mapgen_params) {
119-
errorstream << "saveMapMeta: mapgen_params not present!" << std::endl;
119+
infostream << "saveMapMeta: mapgen_params not present! "
120+
<< "Server startup was probably interrupted." << std::endl;
120121
return false;
121122
}
122123

‎src/server.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ Server::~Server()
351351
// Deinitialize scripting
352352
infostream << "Server: Deinitializing scripting" << std::endl;
353353
delete m_script;
354+
delete m_startup_server_map; // if available
354355
delete m_game_settings;
355356

356357
while (!m_unsent_map_edit_queue.empty()) {
@@ -399,6 +400,7 @@ void Server::init()
399400

400401
// Create the Map (loads map_meta.txt, overriding configured mapgen params)
401402
ServerMap *servermap = new ServerMap(m_path_world, this, m_emerge, m_metrics_backend.get());
403+
m_startup_server_map = servermap;
402404

403405
// Initialize scripting
404406
infostream << "Server: Initializing Lua" << std::endl;
@@ -440,6 +442,7 @@ void Server::init()
440442
m_craftdef->initHashes(this);
441443

442444
// Initialize Environment
445+
m_startup_server_map = nullptr; // Ownership moved to ServerEnvironment
443446
m_env = new ServerEnvironment(servermap, m_script, this, m_path_world);
444447

445448
m_inventory_mgr->setEnv(m_env);

‎src/server.h

+4
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,10 @@ class Server : public con::PeerHandler, public MapEventReceiver,
547547
// Environment
548548
ServerEnvironment *m_env = nullptr;
549549

550+
// Reference to the server map until ServerEnvironment is initialized
551+
// after that this variable must be a nullptr
552+
ServerMap *m_startup_server_map = nullptr;
553+
550554
// server connection
551555
std::shared_ptr<con::Connection> m_con;
552556

0 commit comments

Comments
 (0)
Please sign in to comment.