Skip to content

Commit

Permalink
Fix use-after-free in task_wait_event::signal
Browse files Browse the repository at this point in the history
  • Loading branch information
Amanieu committed Feb 1, 2020
1 parent 2af276d commit 172ca3f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/task_wait_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@ class task_wait_event {
{
std::unique_lock<std::mutex> lock(mutex());
event_mask |= event;
lock.unlock();

// This must be done while holding the lock otherwise we may end up with
// a use-after-free due to a race with wait().
cond().notify_one();
lock.unlock();
}
};

Expand Down

1 comment on commit 172ca3f

@zerodefect
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting! I wonder if I don't observe that because I use my own custom scheduler?

Please sign in to comment.