fix(heap): Fix heap size error

1. get real memory block size when malloc
2. return directly when free freed memory block
This commit is contained in:
Dong Heng
2018-09-25 15:27:25 +08:00
parent 447a2d9406
commit 4c29801ed0
2 changed files with 4 additions and 5 deletions

View File

@ -181,6 +181,7 @@ void *_heap_caps_malloc(size_t size, uint32_t caps, const char *file, size_t lin
ESP_EARLY_LOGV(TAG, "free_blk is %p", g_heap_region[num].free_blk);
}
mem_blk_size = blk_link_size(mem_blk);
g_heap_region[num].free_bytes -= mem_blk_size;
if (g_heap_region[num].min_free_bytes > g_heap_region[num].free_bytes)
@ -238,12 +239,10 @@ void _heap_caps_free(void *ptr, const char *file, size_t line)
}
mem_blk = ptr2blk(ptr, ptr_is_traced(ptr));
#ifdef CONFIG_ESP_HEAP_CHECK_FREED
if (mem_blk->prev) {
ESP_EARLY_LOGE("%p already freed\n", ptr);
if (!mem_blk_is_used(mem_blk)) {
ESP_EARLY_LOGE(TAG, "%p already freed\n", ptr);
return;
}
#endif
ESP_EARLY_LOGV(TAG, "Free(ptr=%p, mem_blk=%p, region=%d)", ptr, mem_blk, num);