Skip to content

Commit

Permalink
zephyr: alloc: virtual_heap_free: Panic on deallocations errors
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
softwarecki committed Jan 16, 2025
1 parent d0930c8 commit 8cc43a9
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion zephyr/lib/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 8cc43a9

Please sign in to comment.