Don't allocate another header when merging chunks

In the nano version of malloc, when the last chunk is to be extended,
there is no need to acount for the header again as it's already taken
into account in the overall "alloc_size" at the beginning of the
function.

Contributed by STMicroelectronics

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
This commit is contained in:
Torbjörn SVENSSON 2022-08-30 15:56:26 +02:00 committed by Jeff Johnston
parent 0455ea28ce
commit a68e99f883
1 changed files with 0 additions and 4 deletions

View File

@ -328,10 +328,6 @@ void * nano_malloc(RARG malloc_size_t s)
/* The last free item has the heap end as neighbour. /* The last free item has the heap end as neighbour.
* Let's ask for a smaller amount and merge */ * Let's ask for a smaller amount and merge */
alloc_size -= p->size; alloc_size -= p->size;
alloc_size = ALIGN_SIZE(alloc_size, CHUNK_ALIGN); /* size of aligned data load */
alloc_size += MALLOC_PADDING; /* padding */
alloc_size += CHUNK_OFFSET; /* size of chunk head */
alloc_size = MAX(alloc_size, MALLOC_MINCHUNK);
if (sbrk_aligned(RCALL alloc_size) != (void *)-1) if (sbrk_aligned(RCALL alloc_size) != (void *)-1)
{ {