Skip to content

Commit 806097c

Browse files
authored
Merge pull request #120 from jannic-dev-forks/issue-119
Fix panic in tlsf::Heap::used()
2 parents df8e527 + caa9a1c commit 806097c

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [Unreleased]
9+
10+
### Fixed
11+
12+
- Fix panic in `tlsf::Heap::used`.
13+
814
## [v0.7.0] - 2026-01-03
915

1016
### Added

examples/tlsf_integration_test.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ pub type TestTable<'a> = &'a [(fn() -> (), &'static str)];
3333

3434
fn test_global_heap() {
3535
const ELEMS: usize = 250;
36+
assert_eq!(HEAP_SIZE, HEAP.free() + HEAP.used());
37+
let initial_free = HEAP.free();
3638

3739
let mut allocated = LinkedList::new();
3840
for _ in 0..ELEMS {
@@ -51,6 +53,8 @@ fn test_global_heap() {
5153
for i in 0..ELEMS {
5254
assert_eq!(allocated.pop_front().unwrap(), i as i32);
5355
}
56+
assert_eq!(HEAP_SIZE, HEAP.free() + HEAP.used());
57+
assert_eq!(initial_free, HEAP.free());
5458
}
5559

5660
fn test_allocator_api() {

src/tlsf.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ impl Heap {
101101
/// Get the amount of bytes used by the allocator.
102102
pub fn used(&self) -> usize {
103103
critical_section::with(|cs| {
104-
self.heap.borrow_ref_mut(cs).raw_block_size - self.free_with_cs(cs)
104+
let free = self.free_with_cs(cs);
105+
self.heap.borrow_ref_mut(cs).raw_block_size - free
105106
})
106107
}
107108

0 commit comments

Comments
 (0)