From 73e4e4fd03c62d5f216b3ec21ab4960c2e1d404f Mon Sep 17 00:00:00 2001 From: pca006132 Date: Thu, 27 Aug 2020 17:02:19 +0800 Subject: [PATCH] libcortex_a9/sync_channel: fixed memory leak ptr::drop_in_place would not drop the box content properly, the best way is to convert it back to a box and implicitly drop it. --- libcortex_a9/src/sync_channel.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libcortex_a9/src/sync_channel.rs b/libcortex_a9/src/sync_channel.rs index 139c8fb..e21df16 100644 --- a/libcortex_a9/src/sync_channel.rs +++ b/libcortex_a9/src/sync_channel.rs @@ -1,7 +1,6 @@ use core::{ pin::Pin, future::Future, - ptr::drop_in_place, sync::atomic::{AtomicPtr, AtomicUsize, Ordering}, task::{Context, Poll}, }; @@ -38,7 +37,7 @@ impl<'a, T> Sender<'a, T> where T: Clone { notify_spin_lock(); if !prev.is_null() { unsafe { - drop_in_place(prev); + Box::from_raw(prev); } } Ok(()) @@ -92,7 +91,7 @@ impl<'a, T> Sender<'a, T> where T: Clone { for v in self.list.iter() { let original = v.swap(core::ptr::null_mut(), Ordering::Relaxed); if !original.is_null() { - drop_in_place(original); + Box::from_raw(original); } } }