From ee0a82be1b9e0c4892f53b571b3b61a2b193edb9 Mon Sep 17 00:00:00 2001 From: Moral-Hao Date: Sun, 6 Aug 2023 14:07:44 +0800 Subject: [PATCH] Fix bug of heap_2 introduced by pr738. (#743) * Fix bug of heap_2 introduced by pr738. * Fix formatting check Signed-off-by: Gaurav Aggarwal --------- Signed-off-by: Gaurav Aggarwal Co-authored-by: moral-hao <405197809@qq.com> Co-authored-by: Gaurav Aggarwal --- portable/MemMang/heap_2.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/portable/MemMang/heap_2.c b/portable/MemMang/heap_2.c index 5c3cb55b16..c041443957 100644 --- a/portable/MemMang/heap_2.c +++ b/portable/MemMang/heap_2.c @@ -229,9 +229,10 @@ void * pvPortMalloc( size_t xWantedSize ) pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize; pxBlock->xBlockSize = xWantedSize; - /* Insert the new block into the list of free blocks. */ - pxNewBlockLink->pxNextFreeBlock = pxPreviousBlock->pxNextFreeBlock; - pxPreviousBlock->pxNextFreeBlock = pxNewBlockLink; + /* Insert the new block into the list of free blocks. + * The list of free blocks is sorted by their size, we have to + * iterate to find the right place to insert new block. */ + prvInsertBlockIntoFreeList( ( pxNewBlockLink ) ); } xFreeBytesRemaining -= pxBlock->xBlockSize;