From ba2200eab8fb209c09da3ca227e963e74d813bf4 Mon Sep 17 00:00:00 2001 From: zachs18 <8355914+zachs18@users.noreply.github.com> Date: Tue, 9 Jan 2024 16:46:45 -0600 Subject: [PATCH] Fix deallocation with wrong allocator in Rc::from_box_in --- library/alloc/src/rc.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 263b1449de156..f5a70504d1f3e 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -1910,7 +1910,10 @@ impl Rc { } #[cfg(not(no_global_oom_handling))] - fn from_box_in(src: Box) -> Rc { + fn from_box_in(src: Box) -> Rc + where + A: Clone, + { unsafe { let value_size = size_of_val(&*src); let ptr = Self::allocate_for_ptr_in(&*src, Box::allocator(&src)); @@ -1924,7 +1927,7 @@ impl Rc { // Free the allocation without dropping its contents let (bptr, alloc) = Box::into_raw_with_allocator(src); - let src = Box::from_raw(bptr as *mut mem::ManuallyDrop); + let src = Box::from_raw_in(bptr as *mut mem::ManuallyDrop, alloc.clone()); drop(src); Self::from_ptr_in(ptr, alloc)