aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyril Yared <yaredcyril@gmail.com>2022-01-25 07:44:10 -0800
committerCorinna Vinschen <corinna@vinschen.de>2022-01-26 13:14:03 +0100
commit73d515fcfecd1004ccffef8fcd0c7223b9eec6ab (patch)
treea595e6622d25581f0e8a84cee3702d6ac8ddd7ed
parent43ab30fbd50cd6394b6b6950647ce2c243fa80c5 (diff)
downloadnewlib-73d515fcfecd1004ccffef8fcd0c7223b9eec6ab.zip
newlib-73d515fcfecd1004ccffef8fcd0c7223b9eec6ab.tar.gz
newlib-73d515fcfecd1004ccffef8fcd0c7223b9eec6ab.tar.bz2
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.
-rw-r--r--newlib/libc/stdlib/nano-mallocr.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/newlib/libc/stdlib/nano-mallocr.c b/newlib/libc/stdlib/nano-mallocr.c
index 6fb08a6..0c5fb28 100644
--- a/newlib/libc/stdlib/nano-mallocr.c
+++ b/newlib/libc/stdlib/nano-mallocr.c
@@ -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 */