Skip to content

Commit 18a168b

Browse files
Saiiijchanwangfei_chen
and
wangfei_chen
authored
Add heap protector to allocted heap blocks (FreeRTOS#1125)
When validate those allocated heap block structure, the canary is not used. Do xor with canary when allocating a new block. Signed-off-by: wangfei_chen <wangfei_chen@realsil.com.cn> Co-authored-by: wangfei_chen <wangfei_chen@realsil.com.cn>
1 parent e43553a commit 18a168b

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

portable/MemMang/heap_4.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ void * pvPortMalloc( size_t xWantedSize )
308308
/* The block is being returned - it is allocated and owned
309309
* by the application and has no "next" block. */
310310
heapALLOCATE_BLOCK( pxBlock );
311-
pxBlock->pxNextFreeBlock = NULL;
311+
pxBlock->pxNextFreeBlock = heapPROTECT_BLOCK_POINTER( NULL );
312312
xNumberOfSuccessfulAllocations++;
313313
}
314314
else
@@ -367,11 +367,11 @@ void vPortFree( void * pv )
367367

368368
heapVALIDATE_BLOCK_POINTER( pxLink );
369369
configASSERT( heapBLOCK_IS_ALLOCATED( pxLink ) != 0 );
370-
configASSERT( pxLink->pxNextFreeBlock == NULL );
370+
configASSERT( pxLink->pxNextFreeBlock == heapPROTECT_BLOCK_POINTER( NULL ) );
371371

372372
if( heapBLOCK_IS_ALLOCATED( pxLink ) != 0 )
373373
{
374-
if( pxLink->pxNextFreeBlock == NULL )
374+
if( pxLink->pxNextFreeBlock == heapPROTECT_BLOCK_POINTER( NULL ) )
375375
{
376376
/* The block is being returned to the heap - it is no longer
377377
* allocated. */

portable/MemMang/heap_5.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ void * pvPortMalloc( size_t xWantedSize )
336336
/* The block is being returned - it is allocated and owned
337337
* by the application and has no "next" block. */
338338
heapALLOCATE_BLOCK( pxBlock );
339-
pxBlock->pxNextFreeBlock = NULL;
339+
pxBlock->pxNextFreeBlock = heapPROTECT_BLOCK_POINTER( NULL );
340340
xNumberOfSuccessfulAllocations++;
341341
}
342342
else
@@ -395,11 +395,11 @@ void vPortFree( void * pv )
395395

396396
heapVALIDATE_BLOCK_POINTER( pxLink );
397397
configASSERT( heapBLOCK_IS_ALLOCATED( pxLink ) != 0 );
398-
configASSERT( pxLink->pxNextFreeBlock == NULL );
398+
configASSERT( pxLink->pxNextFreeBlock == heapPROTECT_BLOCK_POINTER( NULL ) );
399399

400400
if( heapBLOCK_IS_ALLOCATED( pxLink ) != 0 )
401401
{
402-
if( pxLink->pxNextFreeBlock == NULL )
402+
if( pxLink->pxNextFreeBlock == heapPROTECT_BLOCK_POINTER( NULL ) )
403403
{
404404
/* The block is being returned to the heap - it is no longer
405405
* allocated. */

0 commit comments

Comments
 (0)