From 8cc43a9e007fcf5e61dddb29192739d6a60597d3 Mon Sep 17 00:00:00 2001 From: Adrian Warecki Date: Wed, 15 Jan 2025 16:19:38 +0100 Subject: [PATCH] zephyr: alloc: virtual_heap_free: Panic on deallocations errors Add k_panic() function call in error handling code to help detect potential memory release errors. The vmh_free function returns an error if: 1. heap belongs to another core, 2. given pointer to be freed is invalid (doesn't belong to the allocator), 3. there is an error in the code determining the size of the block to be freed 4. memory unmapping fails. Log entry is easy to miss, stopping the firmware at this point will draw attention to a critical problem related to memory allocation. Otherwise, it will have a slowly progressing memory leak. Signed-off-by: Adrian Warecki --- zephyr/lib/alloc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/zephyr/lib/alloc.c b/zephyr/lib/alloc.c index 8bfe3155477d..3cfc6eb97296 100644 --- a/zephyr/lib/alloc.c +++ b/zephyr/lib/alloc.c @@ -257,8 +257,10 @@ static void virtual_heap_free(void *ptr) ptr = (__sparse_force void *)sys_cache_cached_ptr_get(ptr); ret = vmh_free(heap, ptr); - if (ret) + if (ret) { tr_err(&zephyr_tr, "Unable to free %p! %d", ptr, ret); + k_panic(); + } } static const struct vmh_heap_config static_hp_buffers = {