Index: src/freertos/cmpctmalloc.c |
diff --git a/src/freertos/cmpctmalloc.c b/src/freertos/cmpctmalloc.c |
index 790c7341f8047887c3efd19e057fec46b0613d8f..5e8c3644a2f5664324cb8e6d69c7f980195c7e63 100644 |
--- a/src/freertos/cmpctmalloc.c |
+++ b/src/freertos/cmpctmalloc.c |
@@ -624,7 +624,9 @@ static void *large_alloc(size_t size) |
size = ROUNDUP(size, 8); |
free_t *free_area = NULL; |
lock(); |
- heap_grow(size, &free_area); |
+ if (heap_grow(size, &free_area) < 0) { |
+ return 0; |
+ } |
void *result = |
create_allocation_header(free_area, 0, free_area->header.size, free_area->header.left); |
// Normally the 'remaining free space' counter would be decremented when we |
@@ -636,7 +638,8 @@ static void *large_alloc(size_t size) |
unlock(); |
#ifdef CMPCT_DEBUG |
memset(result, ALLOC_FILL, requested_size); |
- memset((char *)result + requested_size, PADDING_FILL, free_area->header.size - requested_size); |
+ memset((char *)result + requested_size, PADDING_FILL, |
+ free_area->header.size - (requested_size + sizeof(header_t))); |
#endif |
return result; |
} |
@@ -868,8 +871,8 @@ static ssize_t heap_grow(size_t size, free_t **bucket) |
size += 2 * sizeof(header_t); |
size = ROUNDUP(size, PAGE_SIZE); |
void *ptr = page_alloc(size >> PAGE_SIZE_SHIFT, ANY_ARENA); |
- theheap.size += size; |
if (ptr == NULL) return -1; |
+ theheap.size += size; |
LTRACEF("growing heap by 0x%zx bytes, new ptr %p\n", size, ptr); |
add_to_heap(ptr, size, bucket); |
return size; |