summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2022-04-28 09:57:41 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2022-05-04 15:57:37 +0200
commitbe5d2bc03d2c5d86489cb24d3b88e95a4b1221f8 (patch)
treede278201be20d43c2b70f57363861272e3279be3
parentimfs: Fix index underrun when extending empty file (diff)
downloadrtems-be5d2bc03d2c5d86489cb24d3b88e95a4b1221f8.tar.bz2
heap: Fix heap statistics with protection enabled
Close #4643.
-rw-r--r--cpukit/include/rtems/score/heapimpl.h10
-rw-r--r--cpukit/score/src/heapallocate.c9
-rw-r--r--testsuites/libtests/malloctest/init.c4
3 files changed, 14 insertions, 9 deletions
diff --git a/cpukit/include/rtems/score/heapimpl.h b/cpukit/include/rtems/score/heapimpl.h
index d3ee0ff88a..f74b5fc562 100644
--- a/cpukit/include/rtems/score/heapimpl.h
+++ b/cpukit/include/rtems/score/heapimpl.h
@@ -407,15 +407,7 @@ Heap_Block *_Heap_Block_allocate(
(*heap->Protection.block_error)( heap, block, reason );
}
- static inline void _Heap_Protection_free_all_delayed_blocks( Heap_Control *heap )
- {
- uintptr_t large = 0
- - (uintptr_t) HEAP_BLOCK_HEADER_SIZE
- - (uintptr_t) HEAP_ALLOC_BONUS
- - (uintptr_t) 1;
- void *p = _Heap_Allocate( heap, large );
- _Heap_Free( heap, p );
- }
+ void _Heap_Protection_free_all_delayed_blocks( Heap_Control *heap );
#endif
/**
diff --git a/cpukit/score/src/heapallocate.c b/cpukit/score/src/heapallocate.c
index 4b8b3f0de6..1c71e4a037 100644
--- a/cpukit/score/src/heapallocate.c
+++ b/cpukit/score/src/heapallocate.c
@@ -73,6 +73,15 @@
return search_again;
}
+
+ void _Heap_Protection_free_all_delayed_blocks( Heap_Control *heap )
+ {
+ bool search_again;
+
+ do {
+ search_again = _Heap_Protection_free_delayed_blocks( heap, 0 );
+ } while ( search_again );
+ }
#endif
#ifdef RTEMS_HEAP_DEBUG
diff --git a/testsuites/libtests/malloctest/init.c b/testsuites/libtests/malloctest/init.c
index 1d91385683..1e5c14fe4b 100644
--- a/testsuites/libtests/malloctest/init.c
+++ b/testsuites/libtests/malloctest/init.c
@@ -122,9 +122,13 @@ static void test_heap_default_init(void)
static void test_free( void *addr )
{
+ uint32_t failed_allocs;
+
rtems_test_assert( _Heap_Free( &TestHeap, addr ) );
+ failed_allocs = TestHeap.stats.failed_allocs;
_Heap_Protection_free_all_delayed_blocks( &TestHeap );
+ rtems_test_assert( failed_allocs == TestHeap.stats.failed_allocs );
}
static void test_heap_cases_1(void)