Skip to content

Commit ee3cea3

Browse files
committed
rust: fix drop in RevocableMutex
Calling `drop_in_place` on a `ManuallyDrop<T>` is a no-op. This commit switches the code to call `ManuallDrop::drop` instead, which actually drops the inner `T`. Signed-off-by: Wedson Almeida Filho <[email protected]>
1 parent 73bd4bb commit ee3cea3

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

rust/kernel/sync/revocable_mutex.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use core::{
1111
mem::ManuallyDrop,
1212
ops::{Deref, DerefMut},
1313
pin::Pin,
14-
ptr::drop_in_place,
1514
};
1615

1716
/// The state within a `RevocableMutex` that is protected by a mutex.
@@ -138,10 +137,11 @@ impl<T: ?Sized> RevocableMutex<T> {
138137
return;
139138
}
140139

141-
// SAFETY: We know `inner.data` is valid because `is_available` is set to true. We'll drop
142-
// it here and set it to false so it isn't dropped again.
143-
unsafe { drop_in_place(&mut inner.data) };
144140
inner.is_available = false;
141+
142+
// SAFETY: We know `inner.data` is valid because `is_available` was true. We'll drop it
143+
// here, and given that we set `is_available` to false above, it won't be dropped again.
144+
unsafe { ManuallyDrop::drop(&mut inner.data) };
145145
}
146146
}
147147

0 commit comments

Comments
 (0)