Commit 1ee96e982a6f93f88e276847b0bae4c5918fb7fb

Authored by Wiebe Cazemier
1 parent 1b3c90ae

Fix crash on config reload when there is no config

configfileparser.cpp
@@ -445,5 +445,12 @@ void ConfigFileParser::loadFile(bool test) @@ -445,5 +445,12 @@ void ConfigFileParser::loadFile(bool test)
445 } 445 }
446 } 446 }
447 447
  448 +std::unique_ptr<Settings> ConfigFileParser::moveSettings()
  449 +{
  450 + std::unique_ptr<Settings> tmp = std::move(settings);
  451 + settings.reset(new Settings);
  452 + return tmp;
  453 +}
  454 +
448 455
449 456
configfileparser.h
@@ -44,6 +44,8 @@ class ConfigFileParser @@ -44,6 +44,8 @@ class ConfigFileParser
44 std::set<std::string> validKeys; 44 std::set<std::string> validKeys;
45 std::set<std::string> validListenKeys; 45 std::set<std::string> validListenKeys;
46 46
  47 + std::unique_ptr<Settings> settings;
  48 +
47 void testKeyValidity(const std::string &key, const std::set<std::string> &validKeys) const; 49 void testKeyValidity(const std::string &key, const std::set<std::string> &validKeys) const;
48 void checkFileExistsAndReadable(const std::string &key, const std::string &pathToCheck, ssize_t max_size = std::numeric_limits<ssize_t>::max()) const; 50 void checkFileExistsAndReadable(const std::string &key, const std::string &pathToCheck, ssize_t max_size = std::numeric_limits<ssize_t>::max()) const;
49 void checkFileOrItsDirWritable(const std::string &filepath) const; 51 void checkFileOrItsDirWritable(const std::string &filepath) const;
@@ -51,7 +53,7 @@ public: @@ -51,7 +53,7 @@ public:
51 ConfigFileParser(const std::string &path); 53 ConfigFileParser(const std::string &path);
52 void loadFile(bool test); 54 void loadFile(bool test);
53 55
54 - std::unique_ptr<Settings> settings; 56 + std::unique_ptr<Settings> moveSettings();
55 }; 57 };
56 58
57 #endif // CONFIGFILEPARSER_H 59 #endif // CONFIGFILEPARSER_H
mainapp.cpp
@@ -628,7 +628,7 @@ void MainApp::loadConfig() @@ -628,7 +628,7 @@ void MainApp::loadConfig()
628 // Atomic loading, first test. 628 // Atomic loading, first test.
629 confFileParser->loadFile(true); 629 confFileParser->loadFile(true);
630 confFileParser->loadFile(false); 630 confFileParser->loadFile(false);
631 - settings = std::move(confFileParser->settings); 631 + settings = confFileParser->moveSettings();
632 632
633 if (settings->listeners.empty()) 633 if (settings->listeners.empty())
634 { 634 {