Skip to content

Commit 3d8b504

Browse files
XuNeoxiaoxiang781216
authored andcommitted
mm: fix kasan report error when delay free is enabled
Signed-off-by: Xu Xingliang <xuxingliang@xiaomi.com>
1 parent bc9d654 commit 3d8b504

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

mm/mm_heap/mm_free.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,18 @@ void mm_delayfree(FAR struct mm_heap_s *heap, FAR void *mem, bool delay)
102102

103103
nodesize = mm_malloc_size(heap, mem);
104104
#ifdef CONFIG_MM_FILL_ALLOCATIONS
105-
memset(mem, MM_FREE_MAGIC, nodesize);
105+
#if CONFIG_MM_FREE_DELAYCOUNT_MAX > 0
106+
/* If delay free is enabled, a memory node will be freed twice.
107+
* The first time is to add the node to the delay list, and the second
108+
* time is to actually free the node. Therefore, we only colorize the
109+
* memory node the first time, when `delay` is set to true.
110+
*/
111+
112+
if (delay)
113+
#endif
114+
{
115+
memset(mem, MM_FREE_MAGIC, nodesize);
116+
}
106117
#endif
107118

108119
kasan_poison(mem, nodesize);

mm/tlsf/mm_tlsf.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,18 @@ static void mm_delayfree(FAR struct mm_heap_s *heap, FAR void *mem,
595595
size_t size = mm_malloc_size(heap, mem);
596596
UNUSED(size);
597597
#ifdef CONFIG_MM_FILL_ALLOCATIONS
598-
memset(mem, MM_FREE_MAGIC, size);
598+
#if CONFIG_MM_FREE_DELAYCOUNT_MAX > 0
599+
/* If delay free is enabled, a memory node will be freed twice.
600+
* The first time is to add the node to the delay list, and the second
601+
* time is to actually free the node. Therefore, we only colorize the
602+
* memory node the first time, when `delay` is set to true.
603+
*/
604+
605+
if (delay)
606+
#endif
607+
{
608+
memset(mem, MM_FREE_MAGIC, nodesize);
609+
}
599610
#endif
600611

601612
kasan_poison(mem, size);

0 commit comments

Comments
 (0)