diff --git a/components/heap/include/priv/esp_heap_caps_priv.h b/components/heap/include/priv/esp_heap_caps_priv.h index 8ed10789..a286f50f 100644 --- a/components/heap/include/priv/esp_heap_caps_priv.h +++ b/components/heap/include/priv/esp_heap_caps_priv.h @@ -123,7 +123,7 @@ static inline bool ptr_is_traced(void *ptr) { uint32_t *p = (uint32_t *)ptr - 1; - return p[0] & 0xf0000000 ? (p[0] == 0xffffffff ? true : false) : true; + return p[0] & 0xf0000000 ? false : true; } static inline mem_blk_t *ptr2blk(void *ptr, bool trace) diff --git a/components/heap/src/esp_heap_caps.c b/components/heap/src/esp_heap_caps.c index db257d28..e1bd8ab8 100644 --- a/components/heap/src/esp_heap_caps.c +++ b/components/heap/src/esp_heap_caps.c @@ -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);