Skip to content

Commit 5829535

Browse files
committed
glib: Don't double-panic if ThreadGuard::into_inner is called on the wrong thread.
1 parent 7ef541b commit 5829535

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

glib/src/thread_guard.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ impl<T> ThreadGuard<T> {
8787
/// created.
8888
#[inline]
8989
pub fn into_inner(self) -> T {
90+
// We wrap `self` in `ManuallyDrop` to defuse `ThreadGuard`'s `Drop` impl.
91+
let mut this = ManuallyDrop::new(self);
92+
9093
assert!(
91-
self.thread_id == thread_id(),
94+
this.thread_id == thread_id(),
9295
"Value accessed from different thread than where it was created"
9396
);
9497

95-
// We wrap `self` in `ManuallyDrop` to defuse `ThreadGuard`'s `Drop` impl.
96-
let mut this = ManuallyDrop::new(self);
97-
9898
// SAFETY: We are on the right thread, and this.value will not be touched after this
9999
unsafe { ManuallyDrop::take(&mut this.value) }
100100
}

0 commit comments

Comments
 (0)