Skip to content

Commit 57382b2

Browse files
committed
Fix a dangling reference in rustc_thread_pool
1 parent e10aa88 commit 57382b2

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

compiler/rustc_thread_pool/src/latch.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,13 +388,16 @@ impl Latch for CountLatch {
388388
#[inline]
389389
unsafe fn set(this: *const Self) {
390390
if unsafe { (*this).counter.fetch_sub(1, Ordering::SeqCst) == 1 } {
391-
// NOTE: Once we call `set` on the internal `latch`,
391+
// SAFETY: Once we call `set` on the internal `latch`,
392392
// the target may proceed and invalidate `this`!
393393
match unsafe { &(*this).kind } {
394394
CountLatchKind::Stealing { latch, registry, worker_index } => {
395395
let registry = Arc::clone(registry);
396+
let worker_index = *worker_index;
396397
if unsafe { CoreLatch::set(latch) } {
397-
registry.notify_worker_latch_is_set(*worker_index);
398+
// We **must not** access any part of `this` anymore,
399+
// which is why we read the fields beforehand.
400+
registry.notify_worker_latch_is_set(worker_index);
398401
}
399402
}
400403
CountLatchKind::Blocking { latch } => unsafe { LockLatch::set(latch) },

0 commit comments

Comments
 (0)