mirror of
https://github.com/rust-embedded/heapless.git
synced 2025-10-02 06:50:32 +00:00
Fix memory leak of MpMcQueue
This commit is contained in:
parent
1f25e658ca
commit
7cfdb8482e
@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
- Fixed the list of implemented data structures in the crate docs, by adding `Deque`,
|
- Fixed the list of implemented data structures in the crate docs, by adding `Deque`,
|
||||||
`HistoryBuffer` and `SortedLinkedList` to the list.
|
`HistoryBuffer` and `SortedLinkedList` to the list.
|
||||||
- Fixed `MpMcQueue` with `mpmc_large` feature.
|
- Fixed `MpMcQueue` with `mpmc_large` feature.
|
||||||
|
- Fix missing `Drop` for `MpMcQueue`
|
||||||
|
|
||||||
## [v0.8.0] - 2023-11-07
|
## [v0.8.0] - 2023-11-07
|
||||||
|
|
||||||
|
19
src/mpmc.rs
19
src/mpmc.rs
@ -194,6 +194,13 @@ impl<T, const N: usize> Default for MpMcQueue<T, N> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T, const N: usize> Drop for MpMcQueue<T, N> {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
// drop all contents currently in the queue
|
||||||
|
while self.dequeue().is_some() {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unsafe impl<T, const N: usize> Sync for MpMcQueue<T, N> where T: Send {}
|
unsafe impl<T, const N: usize> Sync for MpMcQueue<T, N> where T: Send {}
|
||||||
|
|
||||||
struct Cell<T> {
|
struct Cell<T> {
|
||||||
@ -306,6 +313,18 @@ mod tests {
|
|||||||
// Ensure a `MpMcQueue` containing `!Send` values stays `!Send` itself.
|
// Ensure a `MpMcQueue` containing `!Send` values stays `!Send` itself.
|
||||||
assert_not_impl_any!(MpMcQueue<*const (), 4>: Send);
|
assert_not_impl_any!(MpMcQueue<*const (), 4>: Send);
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn memory_leak() {
|
||||||
|
droppable!();
|
||||||
|
|
||||||
|
let q = Q2::new();
|
||||||
|
q.enqueue(Droppable::new()).unwrap_or_else(|_| panic!());
|
||||||
|
q.enqueue(Droppable::new()).unwrap_or_else(|_| panic!());
|
||||||
|
drop(q);
|
||||||
|
|
||||||
|
assert_eq!(Droppable::count(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn sanity() {
|
fn sanity() {
|
||||||
let q = Q2::new();
|
let q = Q2::new();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user