Open
Description
When I was testing with Thread Sanitizer, it kept complaining about this piece of code in rx-subject.hpp and it took a while for me to realize the problem here.
if (b->current_generation != b->state->generation) {
std::unique_lock<std::mutex> guard(b->state->lock);
b->current_generation = b->state->generation;
b->current_completer = b->completer;
}
auto current_completer = b->current_completer;
What happens if Thread-A updates b->current_completer
just before Thread-B assigns b->current_completer
to the local variable? Assuming no one else is holding reference to b->current_completer
, the instance will be destroyed by Thread-A and Thread-B may start operating on the destructed heap space. Can you confirm?
The obvious solution is to not depend on generation numbers and always acquire the mutex and assign b->completer
to a local variable. I can submit a patch if we agree on the issue and a possible solution.
Metadata
Metadata
Assignees
Labels
No labels