Skip to content

Commit 89495f3

Browse files
committed
Forget Waker when cloning LocalWaker
Since NonNull is Copy the inner field of the cloned Waker was copied for use in the new LocalWaker, however this left Waker to be dropped. Which means that when cloning LocalWaker would also erroneously call drop_raw. This change forgets the Waker, rather then dropping it, leaving the inner field to be used by the returned LocalWaker. Closes #52629.
1 parent 3b77203 commit 89495f3

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/libcore/task/wake.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
reason = "futures in libcore are unstable",
1313
issue = "50547")]
1414

15-
use fmt;
15+
use {fmt, mem};
1616
use marker::Unpin;
1717
use ptr::NonNull;
1818

@@ -166,9 +166,10 @@ impl From<LocalWaker> for Waker {
166166
impl Clone for LocalWaker {
167167
#[inline]
168168
fn clone(&self) -> Self {
169-
unsafe {
170-
LocalWaker { inner: self.inner.as_ref().clone_raw().inner }
171-
}
169+
let waker = unsafe { self.inner.as_ref().clone_raw() };
170+
let inner = waker.inner;
171+
mem::forget(waker);
172+
LocalWaker { inner }
172173
}
173174
}
174175

0 commit comments

Comments
 (0)