mm: fix kasan report error when delay free is enabled

Signed-off-by: Xu Xingliang <xuxingliang@xiaomi.com>
This commit is contained in:
Xu Xingliang 2024-03-21 10:37:37 +08:00 committed by Xiang Xiao
parent bc9d6549e9
commit 3d8b504779
2 changed files with 24 additions and 2 deletions

View file

@ -102,7 +102,18 @@ void mm_delayfree(FAR struct mm_heap_s *heap, FAR void *mem, bool delay)
nodesize = mm_malloc_size(heap, mem);
#ifdef CONFIG_MM_FILL_ALLOCATIONS
memset(mem, MM_FREE_MAGIC, nodesize);
#if CONFIG_MM_FREE_DELAYCOUNT_MAX > 0
/* If delay free is enabled, a memory node will be freed twice.
* The first time is to add the node to the delay list, and the second
* time is to actually free the node. Therefore, we only colorize the
* memory node the first time, when `delay` is set to true.
*/
if (delay)
#endif
{
memset(mem, MM_FREE_MAGIC, nodesize);
}
#endif
kasan_poison(mem, nodesize);

View file

@ -595,7 +595,18 @@ static void mm_delayfree(FAR struct mm_heap_s *heap, FAR void *mem,
size_t size = mm_malloc_size(heap, mem);
UNUSED(size);
#ifdef CONFIG_MM_FILL_ALLOCATIONS
memset(mem, MM_FREE_MAGIC, size);
#if CONFIG_MM_FREE_DELAYCOUNT_MAX > 0
/* If delay free is enabled, a memory node will be freed twice.
* The first time is to add the node to the delay list, and the second
* time is to actually free the node. Therefore, we only colorize the
* memory node the first time, when `delay` is set to true.
*/
if (delay)
#endif
{
memset(mem, MM_FREE_MAGIC, nodesize);
}
#endif
kasan_poison(mem, size);