Skip to content

Commit 81685e9

Browse files
committed
Do not create dangling &T in Weak<T>::drop
1 parent 158f8d0 commit 81685e9

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

library/alloc/src/rc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2042,7 +2042,7 @@ impl<T: ?Sized> Drop for Weak<T> {
20422042
// the strong pointers have disappeared.
20432043
if inner.weak() == 0 {
20442044
unsafe {
2045-
Global.deallocate(self.ptr.cast(), Layout::for_value(self.ptr.as_ref()));
2045+
Global.deallocate(self.ptr.cast(), Layout::for_value_raw(self.ptr.as_ptr()));
20462046
}
20472047
}
20482048
}

library/alloc/src/sync.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1927,7 +1927,7 @@ impl<T: ?Sized> Drop for Weak<T> {
19271927

19281928
if inner.weak.fetch_sub(1, Release) == 1 {
19291929
acquire!(inner.weak);
1930-
unsafe { Global.deallocate(self.ptr.cast(), Layout::for_value(self.ptr.as_ref())) }
1930+
unsafe { Global.deallocate(self.ptr.cast(), Layout::for_value_raw(self.ptr.as_ptr())) }
19311931
}
19321932
}
19331933
}

0 commit comments

Comments
 (0)