Skip to content

Commit

Permalink
regions_mm: vmh_free: Prevent null pointer dereference
Browse files Browse the repository at this point in the history
The vmh_free function may have referenced a null pointer if an invalid
pointer to be freed was passed to it. Before referencing the allocator
array item, check if it has been initialized.

Signed-off-by: Adrian Warecki <[email protected]>
  • Loading branch information
softwarecki authored and kv2019i committed Jan 17, 2025
1 parent 45d5365 commit 898adc7
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions zephyr/lib/regions_mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,10 @@ int vmh_free(struct vmh_heap *heap, void *ptr)
for (mem_block_iter = 0, ptr_range_found = false;
mem_block_iter < MAX_MEMORY_ALLOCATORS_COUNT;
mem_block_iter++) {
/* continiue so we do not check mem blocks that do not exist */
if (!heap->physical_blocks_allocators[mem_block_iter])
continue;

block_size =
1 << heap->physical_blocks_allocators[mem_block_iter]->info.blk_sz_shift;

Expand Down

0 comments on commit 898adc7

Please sign in to comment.