Skip to content

Commit

Permalink
Merge pull request #44 from fireice-uk/fix-uninit-access
Browse files Browse the repository at this point in the history
Make sure all singletons are set to null and make env a global ptr
  • Loading branch information
fireice-uk committed Oct 17, 2017
2 parents ca7e27b + 76aa167 commit dcd176a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
2 changes: 1 addition & 1 deletion xmrstak/backend/amd/minethd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ __declspec(dllexport)
#endif
std::vector<iBackend*>* xmrstak_start_backend(uint32_t threadOffset, miner_work& pWork, environment& env)
{
environment::inst() = env;
environment::inst(&env);
return amd::minethd::thread_starter(threadOffset, pWork);
}
} // extern "C"
Expand Down
2 changes: 1 addition & 1 deletion xmrstak/backend/nvidia/minethd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ __declspec(dllexport)
#endif
std::vector<iBackend*>* xmrstak_start_backend(uint32_t threadOffset, miner_work& pWork, environment& env)
{
environment::inst() = env;
environment::inst(&env);
return nvidia::minethd::thread_starter(threadOffset, pWork);
}
} // extern "C"
Expand Down
41 changes: 18 additions & 23 deletions xmrstak/misc/environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit dcd176a

Please sign in to comment.