From 1720d3e096696e3947d1225b89016206e4c510df Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 4 Aug 2017 21:47:43 +0300 Subject: [PATCH] Fixed initialization, no need init logs and network if configuration not ready. --- src/App.cpp | 5 ++++- src/Options.cpp | 9 ++++++--- src/Options.h | 3 ++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/App.cpp b/src/App.cpp index 2e7b72ff..de6f2785 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -59,6 +59,9 @@ App::App(int argc, char **argv) : Cpu::init(); m_options = Options::parse(argc, argv); + if (!m_options) { + return; + } Log::init(); @@ -91,7 +94,7 @@ App::~App() int App::exec() { - if (!m_options->isReady()) { + if (!m_options) { return 0; } diff --git a/src/Options.cpp b/src/Options.cpp index a94af60d..1a1e1c69 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -181,11 +181,14 @@ static char *defaultConfigName() Options *Options::parse(int argc, char **argv) { - if (!m_self) { - m_self = new Options(argc, argv); + Options *options = new Options(argc, argv); + if (options->isReady()) { + m_self = options; + return m_self; } - return m_self; + delete options; + return nullptr; } diff --git a/src/Options.h b/src/Options.h index 0b41f5c4..7a6a7339 100644 --- a/src/Options.h +++ b/src/Options.h @@ -57,7 +57,6 @@ public: inline bool background() const { return m_background; } inline bool colors() const { return m_colors; } inline bool doubleHash() const { return m_doubleHash; } - inline bool isReady() const { return m_ready; } inline bool syslog() const { return m_syslog; } inline const char *logFile() const { return m_logFile; } inline const std::vector &pools() const { return m_pools; } @@ -76,6 +75,8 @@ private: Options(int argc, char **argv); ~Options(); + inline bool isReady() const { return m_ready; } + static Options *m_self; bool parseArg(int key, const char *arg);