Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--newlib/libc/stdlib/nano-mallocr.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/newlib/libc/stdlib/nano-mallocr.c b/newlib/libc/stdlib/nano-mallocr.c
index b2273ba60..a2b50facc 100644
--- a/newlib/libc/stdlib/nano-mallocr.c
+++ b/newlib/libc/stdlib/nano-mallocr.c
@@ -333,14 +333,23 @@ void * nano_malloc(RARG malloc_size_t s)
{
p->size += alloc_size;
- /* Remove chunk from free_list */
+ /* Remove chunk from free_list. Since p != NULL there is
+ at least one chunk */
r = free_list;
- while (r && p != r->next)
+ if (r->next == NULL)
{
- r = r->next;
+ /* There is only a single chunk, remove it */
+ free_list = NULL;
+ }
+ else
+ {
+ /* Search for the chunk before the one to be removed */
+ while (p != r->next)
+ {
+ r = r->next;
+ }
+ r->next = NULL;
}
- r->next = NULL;
-
r = p;
}
else