Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Unified Diff: src/freertos/cmpctmalloc.c

Issue 2082983002: Fix cmpctmalloc for large allocations (Closed) Base URL: git@github.com:dartino/sdk.git@master
Patch Set: format Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/freertos/cmpctmalloc_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « no previous file | src/freertos/cmpctmalloc_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698