diff options
author | fireice-uk <fireice-uk@users.noreply.github.com> | 2017-10-17 16:55:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-17 16:55:32 +0100 |
commit | dcd176ada4ed631b0ea2b2762d93d9be3e4307d4 (patch) | |
tree | 724d7320975b1ec5fde8faf954e67bb57b35e077 /xmrstak/misc | |
parent | ca7e27b78477c0d87583dadf4122c5f305283e9c (diff) | |
parent | 76aa1678477f6b1ac90977ff80f0b4b7237f75cf (diff) | |
download | xmr-stak-dcd176ada4ed631b0ea2b2762d93d9be3e4307d4.zip xmr-stak-dcd176ada4ed631b0ea2b2762d93d9be3e4307d4.tar.gz |
Merge pull request #44 from fireice-uk/fix-uninit-access
Make sure all singletons are set to null and make env a global ptr
Diffstat (limited to 'xmrstak/misc')
-rw-r--r-- | xmrstak/misc/environment.hpp | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/xmrstak/misc/environment.hpp b/xmrstak/misc/environment.hpp index 85375b0..99c2db8 100644 --- a/xmrstak/misc/environment.hpp +++ b/xmrstak/misc/environment.hpp @@ -12,35 +12,30 @@ struct params; struct environment { - - static environment& inst() - { - static environment env; - return env; - } - - environment& operator=(const environment& env) + static inline environment& inst(environment* init = nullptr) { - this->pPrinter = env.pPrinter; - this->pglobalStates = env.pglobalStates; - this->pJconfConfig = env.pJconfConfig; - this->pExecutor = env.pExecutor; - this->pParams = env.pParams; - return *this; - } + static environment* env = nullptr; + if(env == nullptr) + { + if(init == nullptr) + env = new environment; + else + env = init; + } - environment() : pPrinter(nullptr), pglobalStates(nullptr) - { + return *env; } + environment() + { + } - printer* pPrinter; - globalStates* pglobalStates; - jconf* pJconfConfig; - executor* pExecutor; - params* pParams; - + printer* pPrinter = nullptr; + globalStates* pglobalStates = nullptr; + jconf* pJconfConfig = nullptr; + executor* pExecutor = nullptr; + params* pParams = nullptr; }; } // namepsace xmrstak |