-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
bugSomething isn't workingSomething isn't working
Description
This is in reference this:
Lines 58 to 62 in c4728e8
| pub fn get(&self) -> Guard<'_, T> { | |
| let inner = self.ptr.load(Ordering::Relaxed).cast_const(); | |
| unsafe { (*inner).refs.take_ref() }; | |
| Guard { _marker: PhantomData, inner } | |
| } |
pub fn get(&self) -> Guard<'_, T> { // 1
let inner = self.ptr.load(Ordering::Relaxed).cast_const(); // 2
unsafe { (*inner).refs.take_ref() }; // 3
Guard { _marker: PhantomData, inner } // 4
}The race condition exists between lines 2 and 3. Suppose thread A finishes line 2, acquiring a pointer to inner and is then pre-empted by the OS before it can increment the ref-count. While thread A is asleep, thread B invokes update, swaps the pointer, decrements the old ref-count, and deletes the old object.
When thread A resumes, inner is now dangling and line 3 triggers a segfault (if you are lucky) or writes randomly to memory (if you are not).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working