]> sourceware.org Git - newlib-cygwin.git/commitdiff
Fix null-pointer dereference in nano-malloc
authorCyril Yared <yaredcyril@gmail.com>
Tue, 25 Jan 2022 15:44:10 +0000 (07:44 -0800)
committerCorinna Vinschen <corinna@vinschen.de>
Wed, 26 Jan 2022 12:14:03 +0000 (13:14 +0100)
If p is NULL, then the free_list is empty and we should return the
correct failure values.

newlib/libc/stdlib/nano-mallocr.c

index 6fb08a61607358e4897937892b46d9d8edacb844..0c5fb2885278085cdeda2ae16d15799873cf061c 100644 (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 */
This page took 0.031283 seconds and 5 git commands to generate.