Skip to content

Commit 76eb443

Browse files
Fix traceMALLOC() allocated bytes (FreeRTOS#1089)
* Fix traceMALLOC() memory count is inaccurate. (FreeRTOS#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. * Create a new variable xAllocatedBlockSize for traceMALLOC() --------- Co-authored-by: Gaurav-Aggarwal-AWS <[email protected]>
1 parent 663eaad commit 76eb443

File tree

14 files changed

+98
-14
lines changed

14 files changed

+98
-14
lines changed

portable/ARMv8M/secure/heap/secure_heap.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ void * pvPortMalloc( size_t xWantedSize )
256256
BlockLink_t * pxNewBlockLink;
257257
void * pvReturn = NULL;
258258
size_t xAdditionalRequiredSize;
259+
size_t xAllocatedBlockSize = 0;
259260

260261
/* If this is the first call to malloc then the heap will require
261262
* initialisation to setup the list of free blocks. */
@@ -374,6 +375,8 @@ void * pvPortMalloc( size_t xWantedSize )
374375
mtCOVERAGE_TEST_MARKER();
375376
}
376377

378+
xAllocatedBlockSize = pxBlock->xBlockSize;
379+
377380
/* The block is being returned - it is allocated and owned by
378381
* the application and has no "next" block. */
379382
secureheapALLOCATE_BLOCK( pxBlock );
@@ -394,7 +397,10 @@ void * pvPortMalloc( size_t xWantedSize )
394397
mtCOVERAGE_TEST_MARKER();
395398
}
396399

397-
traceMALLOC( pvReturn, xWantedSize );
400+
traceMALLOC( pvReturn, xAllocatedBlockSize );
401+
402+
/* Prevent compiler warnings when trace macros are not used. */
403+
( void ) xAllocatedBlockSize;
398404

399405
#if ( secureconfigUSE_MALLOC_FAILED_HOOK == 1 )
400406
{

portable/GCC/ARM_CM23/secure/secure_heap.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ void * pvPortMalloc( size_t xWantedSize )
256256
BlockLink_t * pxNewBlockLink;
257257
void * pvReturn = NULL;
258258
size_t xAdditionalRequiredSize;
259+
size_t xAllocatedBlockSize = 0;
259260

260261
/* If this is the first call to malloc then the heap will require
261262
* initialisation to setup the list of free blocks. */
@@ -374,6 +375,8 @@ void * pvPortMalloc( size_t xWantedSize )
374375
mtCOVERAGE_TEST_MARKER();
375376
}
376377

378+
xAllocatedBlockSize = pxBlock->xBlockSize;
379+
377380
/* The block is being returned - it is allocated and owned by
378381
* the application and has no "next" block. */
379382
secureheapALLOCATE_BLOCK( pxBlock );
@@ -394,7 +397,10 @@ void * pvPortMalloc( size_t xWantedSize )
394397
mtCOVERAGE_TEST_MARKER();
395398
}
396399

397-
traceMALLOC( pvReturn, xWantedSize );
400+
traceMALLOC( pvReturn, xAllocatedBlockSize );
401+
402+
/* Prevent compiler warnings when trace macros are not used. */
403+
( void ) xAllocatedBlockSize;
398404

399405
#if ( secureconfigUSE_MALLOC_FAILED_HOOK == 1 )
400406
{

portable/GCC/ARM_CM33/secure/secure_heap.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ void * pvPortMalloc( size_t xWantedSize )
256256
BlockLink_t * pxNewBlockLink;
257257
void * pvReturn = NULL;
258258
size_t xAdditionalRequiredSize;
259+
size_t xAllocatedBlockSize = 0;
259260

260261
/* If this is the first call to malloc then the heap will require
261262
* initialisation to setup the list of free blocks. */
@@ -374,6 +375,8 @@ void * pvPortMalloc( size_t xWantedSize )
374375
mtCOVERAGE_TEST_MARKER();
375376
}
376377

378+
xAllocatedBlockSize = pxBlock->xBlockSize;
379+
377380
/* The block is being returned - it is allocated and owned by
378381
* the application and has no "next" block. */
379382
secureheapALLOCATE_BLOCK( pxBlock );
@@ -394,7 +397,10 @@ void * pvPortMalloc( size_t xWantedSize )
394397
mtCOVERAGE_TEST_MARKER();
395398
}
396399

397-
traceMALLOC( pvReturn, xWantedSize );
400+
traceMALLOC( pvReturn, xAllocatedBlockSize );
401+
402+
/* Prevent compiler warnings when trace macros are not used. */
403+
( void ) xAllocatedBlockSize;
398404

399405
#if ( secureconfigUSE_MALLOC_FAILED_HOOK == 1 )
400406
{

portable/GCC/ARM_CM35P/secure/secure_heap.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ void * pvPortMalloc( size_t xWantedSize )
256256
BlockLink_t * pxNewBlockLink;
257257
void * pvReturn = NULL;
258258
size_t xAdditionalRequiredSize;
259+
size_t xAllocatedBlockSize = 0;
259260

260261
/* If this is the first call to malloc then the heap will require
261262
* initialisation to setup the list of free blocks. */
@@ -374,6 +375,8 @@ void * pvPortMalloc( size_t xWantedSize )
374375
mtCOVERAGE_TEST_MARKER();
375376
}
376377

378+
xAllocatedBlockSize = pxBlock->xBlockSize;
379+
377380
/* The block is being returned - it is allocated and owned by
378381
* the application and has no "next" block. */
379382
secureheapALLOCATE_BLOCK( pxBlock );
@@ -394,7 +397,10 @@ void * pvPortMalloc( size_t xWantedSize )
394397
mtCOVERAGE_TEST_MARKER();
395398
}
396399

397-
traceMALLOC( pvReturn, xWantedSize );
400+
traceMALLOC( pvReturn, xAllocatedBlockSize );
401+
402+
/* Prevent compiler warnings when trace macros are not used. */
403+
( void ) xAllocatedBlockSize;
398404

399405
#if ( secureconfigUSE_MALLOC_FAILED_HOOK == 1 )
400406
{

portable/GCC/ARM_CM55/secure/secure_heap.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ void * pvPortMalloc( size_t xWantedSize )
256256
BlockLink_t * pxNewBlockLink;
257257
void * pvReturn = NULL;
258258
size_t xAdditionalRequiredSize;
259+
size_t xAllocatedBlockSize = 0;
259260

260261
/* If this is the first call to malloc then the heap will require
261262
* initialisation to setup the list of free blocks. */
@@ -374,6 +375,8 @@ void * pvPortMalloc( size_t xWantedSize )
374375
mtCOVERAGE_TEST_MARKER();
375376
}
376377

378+
xAllocatedBlockSize = pxBlock->xBlockSize;
379+
377380
/* The block is being returned - it is allocated and owned by
378381
* the application and has no "next" block. */
379382
secureheapALLOCATE_BLOCK( pxBlock );
@@ -394,7 +397,10 @@ void * pvPortMalloc( size_t xWantedSize )
394397
mtCOVERAGE_TEST_MARKER();
395398
}
396399

397-
traceMALLOC( pvReturn, xWantedSize );
400+
traceMALLOC( pvReturn, xAllocatedBlockSize );
401+
402+
/* Prevent compiler warnings when trace macros are not used. */
403+
( void ) xAllocatedBlockSize;
398404

399405
#if ( secureconfigUSE_MALLOC_FAILED_HOOK == 1 )
400406
{

portable/GCC/ARM_CM85/secure/secure_heap.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ void * pvPortMalloc( size_t xWantedSize )
256256
BlockLink_t * pxNewBlockLink;
257257
void * pvReturn = NULL;
258258
size_t xAdditionalRequiredSize;
259+
size_t xAllocatedBlockSize = 0;
259260

260261
/* If this is the first call to malloc then the heap will require
261262
* initialisation to setup the list of free blocks. */
@@ -374,6 +375,8 @@ void * pvPortMalloc( size_t xWantedSize )
374375
mtCOVERAGE_TEST_MARKER();
375376
}
376377

378+
xAllocatedBlockSize = pxBlock->xBlockSize;
379+
377380
/* The block is being returned - it is allocated and owned by
378381
* the application and has no "next" block. */
379382
secureheapALLOCATE_BLOCK( pxBlock );
@@ -394,7 +397,10 @@ void * pvPortMalloc( size_t xWantedSize )
394397
mtCOVERAGE_TEST_MARKER();
395398
}
396399

397-
traceMALLOC( pvReturn, xWantedSize );
400+
traceMALLOC( pvReturn, xAllocatedBlockSize );
401+
402+
/* Prevent compiler warnings when trace macros are not used. */
403+
( void ) xAllocatedBlockSize;
398404

399405
#if ( secureconfigUSE_MALLOC_FAILED_HOOK == 1 )
400406
{

portable/IAR/ARM_CM23/secure/secure_heap.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ void * pvPortMalloc( size_t xWantedSize )
256256
BlockLink_t * pxNewBlockLink;
257257
void * pvReturn = NULL;
258258
size_t xAdditionalRequiredSize;
259+
size_t xAllocatedBlockSize = 0;
259260

260261
/* If this is the first call to malloc then the heap will require
261262
* initialisation to setup the list of free blocks. */
@@ -374,6 +375,8 @@ void * pvPortMalloc( size_t xWantedSize )
374375
mtCOVERAGE_TEST_MARKER();
375376
}
376377

378+
xAllocatedBlockSize = pxBlock->xBlockSize;
379+
377380
/* The block is being returned - it is allocated and owned by
378381
* the application and has no "next" block. */
379382
secureheapALLOCATE_BLOCK( pxBlock );
@@ -394,7 +397,10 @@ void * pvPortMalloc( size_t xWantedSize )
394397
mtCOVERAGE_TEST_MARKER();
395398
}
396399

397-
traceMALLOC( pvReturn, xWantedSize );
400+
traceMALLOC( pvReturn, xAllocatedBlockSize );
401+
402+
/* Prevent compiler warnings when trace macros are not used. */
403+
( void ) xAllocatedBlockSize;
398404

399405
#if ( secureconfigUSE_MALLOC_FAILED_HOOK == 1 )
400406
{

portable/IAR/ARM_CM33/secure/secure_heap.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ void * pvPortMalloc( size_t xWantedSize )
256256
BlockLink_t * pxNewBlockLink;
257257
void * pvReturn = NULL;
258258
size_t xAdditionalRequiredSize;
259+
size_t xAllocatedBlockSize = 0;
259260

260261
/* If this is the first call to malloc then the heap will require
261262
* initialisation to setup the list of free blocks. */
@@ -374,6 +375,8 @@ void * pvPortMalloc( size_t xWantedSize )
374375
mtCOVERAGE_TEST_MARKER();
375376
}
376377

378+
xAllocatedBlockSize = pxBlock->xBlockSize;
379+
377380
/* The block is being returned - it is allocated and owned by
378381
* the application and has no "next" block. */
379382
secureheapALLOCATE_BLOCK( pxBlock );
@@ -394,7 +397,10 @@ void * pvPortMalloc( size_t xWantedSize )
394397
mtCOVERAGE_TEST_MARKER();
395398
}
396399

397-
traceMALLOC( pvReturn, xWantedSize );
400+
traceMALLOC( pvReturn, xAllocatedBlockSize );
401+
402+
/* Prevent compiler warnings when trace macros are not used. */
403+
( void ) xAllocatedBlockSize;
398404

399405
#if ( secureconfigUSE_MALLOC_FAILED_HOOK == 1 )
400406
{

portable/IAR/ARM_CM35P/secure/secure_heap.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ void * pvPortMalloc( size_t xWantedSize )
256256
BlockLink_t * pxNewBlockLink;
257257
void * pvReturn = NULL;
258258
size_t xAdditionalRequiredSize;
259+
size_t xAllocatedBlockSize = 0;
259260

260261
/* If this is the first call to malloc then the heap will require
261262
* initialisation to setup the list of free blocks. */
@@ -374,6 +375,8 @@ void * pvPortMalloc( size_t xWantedSize )
374375
mtCOVERAGE_TEST_MARKER();
375376
}
376377

378+
xAllocatedBlockSize = pxBlock->xBlockSize;
379+
377380
/* The block is being returned - it is allocated and owned by
378381
* the application and has no "next" block. */
379382
secureheapALLOCATE_BLOCK( pxBlock );
@@ -394,7 +397,10 @@ void * pvPortMalloc( size_t xWantedSize )
394397
mtCOVERAGE_TEST_MARKER();
395398
}
396399

397-
traceMALLOC( pvReturn, xWantedSize );
400+
traceMALLOC( pvReturn, xAllocatedBlockSize );
401+
402+
/* Prevent compiler warnings when trace macros are not used. */
403+
( void ) xAllocatedBlockSize;
398404

399405
#if ( secureconfigUSE_MALLOC_FAILED_HOOK == 1 )
400406
{

portable/IAR/ARM_CM55/secure/secure_heap.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ void * pvPortMalloc( size_t xWantedSize )
256256
BlockLink_t * pxNewBlockLink;
257257
void * pvReturn = NULL;
258258
size_t xAdditionalRequiredSize;
259+
size_t xAllocatedBlockSize = 0;
259260

260261
/* If this is the first call to malloc then the heap will require
261262
* initialisation to setup the list of free blocks. */
@@ -374,6 +375,8 @@ void * pvPortMalloc( size_t xWantedSize )
374375
mtCOVERAGE_TEST_MARKER();
375376
}
376377

378+
xAllocatedBlockSize = pxBlock->xBlockSize;
379+
377380
/* The block is being returned - it is allocated and owned by
378381
* the application and has no "next" block. */
379382
secureheapALLOCATE_BLOCK( pxBlock );
@@ -394,7 +397,10 @@ void * pvPortMalloc( size_t xWantedSize )
394397
mtCOVERAGE_TEST_MARKER();
395398
}
396399

397-
traceMALLOC( pvReturn, xWantedSize );
400+
traceMALLOC( pvReturn, xAllocatedBlockSize );
401+
402+
/* Prevent compiler warnings when trace macros are not used. */
403+
( void ) xAllocatedBlockSize;
398404

399405
#if ( secureconfigUSE_MALLOC_FAILED_HOOK == 1 )
400406
{

portable/IAR/ARM_CM85/secure/secure_heap.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ void * pvPortMalloc( size_t xWantedSize )
256256
BlockLink_t * pxNewBlockLink;
257257
void * pvReturn = NULL;
258258
size_t xAdditionalRequiredSize;
259+
size_t xAllocatedBlockSize = 0;
259260

260261
/* If this is the first call to malloc then the heap will require
261262
* initialisation to setup the list of free blocks. */
@@ -374,6 +375,8 @@ void * pvPortMalloc( size_t xWantedSize )
374375
mtCOVERAGE_TEST_MARKER();
375376
}
376377

378+
xAllocatedBlockSize = pxBlock->xBlockSize;
379+
377380
/* The block is being returned - it is allocated and owned by
378381
* the application and has no "next" block. */
379382
secureheapALLOCATE_BLOCK( pxBlock );
@@ -394,7 +397,10 @@ void * pvPortMalloc( size_t xWantedSize )
394397
mtCOVERAGE_TEST_MARKER();
395398
}
396399

397-
traceMALLOC( pvReturn, xWantedSize );
400+
traceMALLOC( pvReturn, xAllocatedBlockSize );
401+
402+
/* Prevent compiler warnings when trace macros are not used. */
403+
( void ) xAllocatedBlockSize;
398404

399405
#if ( secureconfigUSE_MALLOC_FAILED_HOOK == 1 )
400406
{

portable/MemMang/heap_2.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ void * pvPortMalloc( size_t xWantedSize )
160160
BlockLink_t * pxNewBlockLink;
161161
void * pvReturn = NULL;
162162
size_t xAdditionalRequiredSize;
163+
size_t xAllocatedBlockSize = 0;
163164

164165
if( xWantedSize > 0 )
165166
{
@@ -261,6 +262,8 @@ void * pvPortMalloc( size_t xWantedSize )
261262

262263
xFreeBytesRemaining -= pxBlock->xBlockSize;
263264

265+
xAllocatedBlockSize = pxBlock->xBlockSize;
266+
264267
/* The block is being returned - it is allocated and owned
265268
* by the application and has no "next" block. */
266269
heapALLOCATE_BLOCK( pxBlock );
@@ -269,7 +272,10 @@ void * pvPortMalloc( size_t xWantedSize )
269272
}
270273
}
271274

272-
traceMALLOC( pvReturn, xWantedSize );
275+
traceMALLOC( pvReturn, xAllocatedBlockSize );
276+
277+
/* Prevent compiler warnings when trace macros are not used. */
278+
( void ) xAllocatedBlockSize;
273279
}
274280
( void ) xTaskResumeAll();
275281

portable/MemMang/heap_4.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ void * pvPortMalloc( size_t xWantedSize )
177177
BlockLink_t * pxNewBlockLink;
178178
void * pvReturn = NULL;
179179
size_t xAdditionalRequiredSize;
180+
size_t xAllocatedBlockSize = 0;
180181

181182
if( xWantedSize > 0 )
182183
{
@@ -302,6 +303,8 @@ void * pvPortMalloc( size_t xWantedSize )
302303
mtCOVERAGE_TEST_MARKER();
303304
}
304305

306+
xAllocatedBlockSize = pxBlock->xBlockSize;
307+
305308
/* The block is being returned - it is allocated and owned
306309
* by the application and has no "next" block. */
307310
heapALLOCATE_BLOCK( pxBlock );
@@ -323,7 +326,10 @@ void * pvPortMalloc( size_t xWantedSize )
323326
mtCOVERAGE_TEST_MARKER();
324327
}
325328

326-
traceMALLOC( pvReturn, xWantedSize );
329+
traceMALLOC( pvReturn, xAllocatedBlockSize );
330+
331+
/* Prevent compiler warnings when trace macros are not used. */
332+
( void ) xAllocatedBlockSize;
327333
}
328334
( void ) xTaskResumeAll();
329335

0 commit comments

Comments
 (0)