From 2d5c193a0f1ab01f1860644e5481c4e02cb14efe Mon Sep 17 00:00:00 2001 From: WangGaoJie Date: Tue, 11 Jun 2024 09:38:27 +0800 Subject: [PATCH] Fix traceMALLOC() memory count is inaccurate. (#1078) Modify xWantedSize to the size of a free block when not split blocks. Ensure that the sizes within traceMALLOC() and traceFREE() macros are equal. --- portable/ARMv8M/secure/heap/secure_heap.c | 5 ++++- portable/GCC/ARM_CM23/secure/secure_heap.c | 5 ++++- portable/GCC/ARM_CM33/secure/secure_heap.c | 5 ++++- portable/GCC/ARM_CM35P/secure/secure_heap.c | 5 ++++- portable/GCC/ARM_CM55/secure/secure_heap.c | 5 ++++- portable/GCC/ARM_CM85/secure/secure_heap.c | 5 ++++- portable/IAR/ARM_CM23/secure/secure_heap.c | 5 ++++- portable/IAR/ARM_CM33/secure/secure_heap.c | 5 ++++- portable/IAR/ARM_CM35P/secure/secure_heap.c | 5 ++++- portable/IAR/ARM_CM55/secure/secure_heap.c | 5 ++++- portable/IAR/ARM_CM85/secure/secure_heap.c | 5 ++++- portable/MemMang/heap_2.c | 7 +++++++ portable/MemMang/heap_4.c | 5 ++++- portable/MemMang/heap_5.c | 5 ++++- 14 files changed, 59 insertions(+), 13 deletions(-) diff --git a/portable/ARMv8M/secure/heap/secure_heap.c b/portable/ARMv8M/secure/heap/secure_heap.c index 4fa6a2ffa..a60679eb1 100644 --- a/portable/ARMv8M/secure/heap/secure_heap.c +++ b/portable/ARMv8M/secure/heap/secure_heap.c @@ -360,7 +360,7 @@ void * pvPortMalloc( size_t xWantedSize ) } else { - mtCOVERAGE_TEST_MARKER(); + xWantedSize = pxBlock->xBlockSize; } xFreeBytesRemaining -= pxBlock->xBlockSize; @@ -396,6 +396,9 @@ void * pvPortMalloc( size_t xWantedSize ) traceMALLOC( pvReturn, xWantedSize ); + /* Prevent compiler warnings when trace macros are not used. */ + ( void ) xWantedSize; + #if ( secureconfigUSE_MALLOC_FAILED_HOOK == 1 ) { if( pvReturn == NULL ) diff --git a/portable/GCC/ARM_CM23/secure/secure_heap.c b/portable/GCC/ARM_CM23/secure/secure_heap.c index 4fa6a2ffa..a60679eb1 100644 --- a/portable/GCC/ARM_CM23/secure/secure_heap.c +++ b/portable/GCC/ARM_CM23/secure/secure_heap.c @@ -360,7 +360,7 @@ void * pvPortMalloc( size_t xWantedSize ) } else { - mtCOVERAGE_TEST_MARKER(); + xWantedSize = pxBlock->xBlockSize; } xFreeBytesRemaining -= pxBlock->xBlockSize; @@ -396,6 +396,9 @@ void * pvPortMalloc( size_t xWantedSize ) traceMALLOC( pvReturn, xWantedSize ); + /* Prevent compiler warnings when trace macros are not used. */ + ( void ) xWantedSize; + #if ( secureconfigUSE_MALLOC_FAILED_HOOK == 1 ) { if( pvReturn == NULL ) diff --git a/portable/GCC/ARM_CM33/secure/secure_heap.c b/portable/GCC/ARM_CM33/secure/secure_heap.c index 4fa6a2ffa..a60679eb1 100644 --- a/portable/GCC/ARM_CM33/secure/secure_heap.c +++ b/portable/GCC/ARM_CM33/secure/secure_heap.c @@ -360,7 +360,7 @@ void * pvPortMalloc( size_t xWantedSize ) } else { - mtCOVERAGE_TEST_MARKER(); + xWantedSize = pxBlock->xBlockSize; } xFreeBytesRemaining -= pxBlock->xBlockSize; @@ -396,6 +396,9 @@ void * pvPortMalloc( size_t xWantedSize ) traceMALLOC( pvReturn, xWantedSize ); + /* Prevent compiler warnings when trace macros are not used. */ + ( void ) xWantedSize; + #if ( secureconfigUSE_MALLOC_FAILED_HOOK == 1 ) { if( pvReturn == NULL ) diff --git a/portable/GCC/ARM_CM35P/secure/secure_heap.c b/portable/GCC/ARM_CM35P/secure/secure_heap.c index 4fa6a2ffa..a60679eb1 100644 --- a/portable/GCC/ARM_CM35P/secure/secure_heap.c +++ b/portable/GCC/ARM_CM35P/secure/secure_heap.c @@ -360,7 +360,7 @@ void * pvPortMalloc( size_t xWantedSize ) } else { - mtCOVERAGE_TEST_MARKER(); + xWantedSize = pxBlock->xBlockSize; } xFreeBytesRemaining -= pxBlock->xBlockSize; @@ -396,6 +396,9 @@ void * pvPortMalloc( size_t xWantedSize ) traceMALLOC( pvReturn, xWantedSize ); + /* Prevent compiler warnings when trace macros are not used. */ + ( void ) xWantedSize; + #if ( secureconfigUSE_MALLOC_FAILED_HOOK == 1 ) { if( pvReturn == NULL ) diff --git a/portable/GCC/ARM_CM55/secure/secure_heap.c b/portable/GCC/ARM_CM55/secure/secure_heap.c index 4fa6a2ffa..a60679eb1 100644 --- a/portable/GCC/ARM_CM55/secure/secure_heap.c +++ b/portable/GCC/ARM_CM55/secure/secure_heap.c @@ -360,7 +360,7 @@ void * pvPortMalloc( size_t xWantedSize ) } else { - mtCOVERAGE_TEST_MARKER(); + xWantedSize = pxBlock->xBlockSize; } xFreeBytesRemaining -= pxBlock->xBlockSize; @@ -396,6 +396,9 @@ void * pvPortMalloc( size_t xWantedSize ) traceMALLOC( pvReturn, xWantedSize ); + /* Prevent compiler warnings when trace macros are not used. */ + ( void ) xWantedSize; + #if ( secureconfigUSE_MALLOC_FAILED_HOOK == 1 ) { if( pvReturn == NULL ) diff --git a/portable/GCC/ARM_CM85/secure/secure_heap.c b/portable/GCC/ARM_CM85/secure/secure_heap.c index 4fa6a2ffa..a60679eb1 100644 --- a/portable/GCC/ARM_CM85/secure/secure_heap.c +++ b/portable/GCC/ARM_CM85/secure/secure_heap.c @@ -360,7 +360,7 @@ void * pvPortMalloc( size_t xWantedSize ) } else { - mtCOVERAGE_TEST_MARKER(); + xWantedSize = pxBlock->xBlockSize; } xFreeBytesRemaining -= pxBlock->xBlockSize; @@ -396,6 +396,9 @@ void * pvPortMalloc( size_t xWantedSize ) traceMALLOC( pvReturn, xWantedSize ); + /* Prevent compiler warnings when trace macros are not used. */ + ( void ) xWantedSize; + #if ( secureconfigUSE_MALLOC_FAILED_HOOK == 1 ) { if( pvReturn == NULL ) diff --git a/portable/IAR/ARM_CM23/secure/secure_heap.c b/portable/IAR/ARM_CM23/secure/secure_heap.c index 4fa6a2ffa..a60679eb1 100644 --- a/portable/IAR/ARM_CM23/secure/secure_heap.c +++ b/portable/IAR/ARM_CM23/secure/secure_heap.c @@ -360,7 +360,7 @@ void * pvPortMalloc( size_t xWantedSize ) } else { - mtCOVERAGE_TEST_MARKER(); + xWantedSize = pxBlock->xBlockSize; } xFreeBytesRemaining -= pxBlock->xBlockSize; @@ -396,6 +396,9 @@ void * pvPortMalloc( size_t xWantedSize ) traceMALLOC( pvReturn, xWantedSize ); + /* Prevent compiler warnings when trace macros are not used. */ + ( void ) xWantedSize; + #if ( secureconfigUSE_MALLOC_FAILED_HOOK == 1 ) { if( pvReturn == NULL ) diff --git a/portable/IAR/ARM_CM33/secure/secure_heap.c b/portable/IAR/ARM_CM33/secure/secure_heap.c index 4fa6a2ffa..a60679eb1 100644 --- a/portable/IAR/ARM_CM33/secure/secure_heap.c +++ b/portable/IAR/ARM_CM33/secure/secure_heap.c @@ -360,7 +360,7 @@ void * pvPortMalloc( size_t xWantedSize ) } else { - mtCOVERAGE_TEST_MARKER(); + xWantedSize = pxBlock->xBlockSize; } xFreeBytesRemaining -= pxBlock->xBlockSize; @@ -396,6 +396,9 @@ void * pvPortMalloc( size_t xWantedSize ) traceMALLOC( pvReturn, xWantedSize ); + /* Prevent compiler warnings when trace macros are not used. */ + ( void ) xWantedSize; + #if ( secureconfigUSE_MALLOC_FAILED_HOOK == 1 ) { if( pvReturn == NULL ) diff --git a/portable/IAR/ARM_CM35P/secure/secure_heap.c b/portable/IAR/ARM_CM35P/secure/secure_heap.c index 4fa6a2ffa..a60679eb1 100644 --- a/portable/IAR/ARM_CM35P/secure/secure_heap.c +++ b/portable/IAR/ARM_CM35P/secure/secure_heap.c @@ -360,7 +360,7 @@ void * pvPortMalloc( size_t xWantedSize ) } else { - mtCOVERAGE_TEST_MARKER(); + xWantedSize = pxBlock->xBlockSize; } xFreeBytesRemaining -= pxBlock->xBlockSize; @@ -396,6 +396,9 @@ void * pvPortMalloc( size_t xWantedSize ) traceMALLOC( pvReturn, xWantedSize ); + /* Prevent compiler warnings when trace macros are not used. */ + ( void ) xWantedSize; + #if ( secureconfigUSE_MALLOC_FAILED_HOOK == 1 ) { if( pvReturn == NULL ) diff --git a/portable/IAR/ARM_CM55/secure/secure_heap.c b/portable/IAR/ARM_CM55/secure/secure_heap.c index 4fa6a2ffa..a60679eb1 100644 --- a/portable/IAR/ARM_CM55/secure/secure_heap.c +++ b/portable/IAR/ARM_CM55/secure/secure_heap.c @@ -360,7 +360,7 @@ void * pvPortMalloc( size_t xWantedSize ) } else { - mtCOVERAGE_TEST_MARKER(); + xWantedSize = pxBlock->xBlockSize; } xFreeBytesRemaining -= pxBlock->xBlockSize; @@ -396,6 +396,9 @@ void * pvPortMalloc( size_t xWantedSize ) traceMALLOC( pvReturn, xWantedSize ); + /* Prevent compiler warnings when trace macros are not used. */ + ( void ) xWantedSize; + #if ( secureconfigUSE_MALLOC_FAILED_HOOK == 1 ) { if( pvReturn == NULL ) diff --git a/portable/IAR/ARM_CM85/secure/secure_heap.c b/portable/IAR/ARM_CM85/secure/secure_heap.c index 4fa6a2ffa..a60679eb1 100644 --- a/portable/IAR/ARM_CM85/secure/secure_heap.c +++ b/portable/IAR/ARM_CM85/secure/secure_heap.c @@ -360,7 +360,7 @@ void * pvPortMalloc( size_t xWantedSize ) } else { - mtCOVERAGE_TEST_MARKER(); + xWantedSize = pxBlock->xBlockSize; } xFreeBytesRemaining -= pxBlock->xBlockSize; @@ -396,6 +396,9 @@ void * pvPortMalloc( size_t xWantedSize ) traceMALLOC( pvReturn, xWantedSize ); + /* Prevent compiler warnings when trace macros are not used. */ + ( void ) xWantedSize; + #if ( secureconfigUSE_MALLOC_FAILED_HOOK == 1 ) { if( pvReturn == NULL ) diff --git a/portable/MemMang/heap_2.c b/portable/MemMang/heap_2.c index c1b35b911..f662614e5 100644 --- a/portable/MemMang/heap_2.c +++ b/portable/MemMang/heap_2.c @@ -258,6 +258,10 @@ void * pvPortMalloc( size_t xWantedSize ) * iterate to find the right place to insert new block. */ prvInsertBlockIntoFreeList( ( pxNewBlockLink ) ); } + else + { + xWantedSize = pxBlock->xBlockSize; + } xFreeBytesRemaining -= pxBlock->xBlockSize; @@ -270,6 +274,9 @@ void * pvPortMalloc( size_t xWantedSize ) } traceMALLOC( pvReturn, xWantedSize ); + + /* Prevent compiler warnings when trace macros are not used. */ + ( void ) xWantedSize; } ( void ) xTaskResumeAll(); diff --git a/portable/MemMang/heap_4.c b/portable/MemMang/heap_4.c index 71b6a9421..c1ce3c1ab 100644 --- a/portable/MemMang/heap_4.c +++ b/portable/MemMang/heap_4.c @@ -288,7 +288,7 @@ void * pvPortMalloc( size_t xWantedSize ) } else { - mtCOVERAGE_TEST_MARKER(); + xWantedSize = pxBlock->xBlockSize; } xFreeBytesRemaining -= pxBlock->xBlockSize; @@ -324,6 +324,9 @@ void * pvPortMalloc( size_t xWantedSize ) } traceMALLOC( pvReturn, xWantedSize ); + + /* Prevent compiler warnings when trace macros are not used. */ + ( void ) xWantedSize; } ( void ) xTaskResumeAll(); diff --git a/portable/MemMang/heap_5.c b/portable/MemMang/heap_5.c index bb33bcfad..0bc44ebd9 100644 --- a/portable/MemMang/heap_5.c +++ b/portable/MemMang/heap_5.c @@ -316,7 +316,7 @@ void * pvPortMalloc( size_t xWantedSize ) } else { - mtCOVERAGE_TEST_MARKER(); + xWantedSize = pxBlock->xBlockSize; } xFreeBytesRemaining -= pxBlock->xBlockSize; @@ -352,6 +352,9 @@ void * pvPortMalloc( size_t xWantedSize ) } traceMALLOC( pvReturn, xWantedSize ); + + /* Prevent compiler warnings when trace macros are not used. */ + ( void ) xWantedSize; } ( void ) xTaskResumeAll();