Skip to content

Commit

Permalink
Rollup merge of rust-lang#52640 - Thomasdezeeuw:fix-localwaker-clone,…
Browse files Browse the repository at this point in the history
… r=cramertj

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 rust-lang#52629.
  • Loading branch information
kennytm authored Jul 24, 2018
2 parents 3af372a + 89495f3 commit b3c9fe2
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/libcore/task/wake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
reason = "futures in libcore are unstable",
issue = "50547")]

use fmt;
use {fmt, mem};
use marker::Unpin;
use ptr::NonNull;

Expand Down Expand Up @@ -166,9 +166,10 @@ impl From<LocalWaker> for Waker {
impl Clone for LocalWaker {
#[inline]
fn clone(&self) -> Self {
unsafe {
LocalWaker { inner: self.inner.as_ref().clone_raw().inner }
}
let waker = unsafe { self.inner.as_ref().clone_raw() };
let inner = waker.inner;
mem::forget(waker);
LocalWaker { inner }
}
}

Expand Down

0 comments on commit b3c9fe2

Please sign in to comment.