diff options
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/main.cpp b/src/main.cpp index 4a69f83b5..ffbdb7b5b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -91,6 +91,7 @@ static void list_worlds(bool print_name, bool print_path); static bool setup_log_params(const Settings &cmd_args); static bool create_userdata_path(); static bool init_common(const Settings &cmd_args, int argc, char *argv[]); +static void uninit_common(); static void startup_message(); static bool read_config_file(const Settings &cmd_args); static void init_log_streams(const Settings &cmd_args); @@ -201,6 +202,7 @@ int main(int argc, char *argv[]) errorstream << "Unittest support is not enabled in this binary. " << "If you want to enable it, compile project with BUILD_UNITTESTS=1 flag." << std::endl; + return 1; #endif } #endif @@ -236,9 +238,6 @@ int main(int argc, char *argv[]) print_modified_quicktune_values(); - // Stop httpfetch thread (if started) - httpfetch_cleanup(); - END_DEBUG_EXCEPTION_HANDLER return retval; @@ -486,13 +485,14 @@ static bool init_common(const Settings &cmd_args, int argc, char *argv[]) startup_message(); set_default_settings(); - // Initialize sockets sockets_init(); - atexit(sockets_cleanup); // Initialize g_settings Settings::createLayer(SL_GLOBAL); + // Set cleanup callback(s) to run at process exit + atexit(uninit_common); + if (!read_config_file(cmd_args)) return false; @@ -511,6 +511,17 @@ static bool init_common(const Settings &cmd_args, int argc, char *argv[]) return true; } +static void uninit_common() +{ + httpfetch_cleanup(); + + sockets_cleanup(); + + // It'd actually be okay to leak these but we want to please valgrind... + for (int i = 0; i < (int)SL_TOTAL_COUNT; i++) + delete Settings::getLayer((SettingsLayer)i); +} + static void startup_message() { infostream << PROJECT_NAME << " " << _("with") |