Skip to content
Snippets Groups Projects
Commit 615f227f authored by Florian Fischer's avatar Florian Fischer
Browse files

initialize the blocked context pointer to prevent undefined unblock

Not initializing blockedContext means its original value is undefined and
probably some random stack value != nullptr.

If the first put() is executed before the first blocking get(), put() will read a
random value from blockedContext and will call unblock with this random context
pointer leading to execution of random memory.
parent 72898ff1
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,7 @@ class UnboundedBlockingMpscQueue : protected Logger<LogSubsystem::U_B_MPSC_Q>
, protected Blockable {
private:
std::atomic<Context*> blockedContext;
std::atomic<Context*> blockedContext = nullptr;
bool tPopped;
T t;
......@@ -27,6 +27,10 @@ private:
}
void tryToGetElement(std::function<void(void)> postRetrieve) {
// tPopped indicates that 't' is a popped and usable value.
// Therefore if we tryToGet a new 't' while 't' is available the current 't'
// would be overridden and dropped.
assert(!tPopped);
std::lock_guard<std::mutex> lock(queueMutex);
if (!mpscQueue.empty()) {
t = mpscQueue.front();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment