Fix null-pointer dereference in nano-malloc

If p is NULL, then the free_list is empty and we should return the
correct failure values.
This commit is contained in:
Cyril Yared 2022-01-25 07:44:10 -08:00 committed by Corinna Vinschen
parent 43ab30fbd5
commit 73d515fcfe
1 changed files with 1 additions and 1 deletions

View File

@ -322,7 +322,7 @@ void * nano_malloc(RARG malloc_size_t s)
r=r->next;
}
if ((char *)p + p->size == (char *)_SBRK_R(RCALL 0))
if (p != NULL && (char *)p + p->size == (char *)_SBRK_R(RCALL 0))
{
/* The last free item has the heap end as neighbour.
* Let's ask for a smaller amount and merge */