mm_heap: check heap member in advance

Block wrong address in advance before entering mempool.

Signed-off-by: pengyiqiang <pengyiqiang@xiaomi.com>
This commit is contained in:
pengyiqiang 2023-08-04 12:10:10 +08:00 committed by Xiang Xiao
parent 98fba71998
commit 8c19fc547d
2 changed files with 4 additions and 3 deletions

View File

@ -84,6 +84,8 @@ void mm_free(FAR struct mm_heap_s *heap, FAR void *mem)
return;
}
DEBUGASSERT(mm_heapmember(heap, mem));
#if CONFIG_MM_HEAP_MEMPOOL_THRESHOLD != 0
if (mempool_multiple_free(heap->mm_mpool, mem) >= 0)
{
@ -104,8 +106,6 @@ void mm_free(FAR struct mm_heap_s *heap, FAR void *mem)
kasan_poison(mem, mm_malloc_size(heap, mem));
DEBUGASSERT(mm_heapmember(heap, mem));
/* Map the memory chunk into a free node */
node = (FAR struct mm_freenode_s *)((FAR char *)mem - SIZEOF_MM_ALLOCNODE);

View File

@ -81,6 +81,8 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem,
return mm_malloc(heap, size);
}
DEBUGASSERT(mm_heapmember(heap, oldmem));
#if CONFIG_MM_HEAP_MEMPOOL_THRESHOLD != 0
newmem = mempool_multiple_realloc(heap->mm_mpool, oldmem, size);
if (newmem != NULL)
@ -129,7 +131,6 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem,
DEBUGVERIFY(mm_lock(heap));
DEBUGASSERT(oldnode->size & MM_ALLOC_BIT);
DEBUGASSERT(mm_heapmember(heap, oldmem));
/* Check if this is a request to reduce the size of the allocation. */