diff --git a/mm/mm_heap/mm_free.c b/mm/mm_heap/mm_free.c index 894719b056f..5513ba17720 100644 --- a/mm/mm_heap/mm_free.c +++ b/mm/mm_heap/mm_free.c @@ -84,12 +84,8 @@ void mm_free(FAR struct mm_heap_s *heap, FAR void *mem) return; } - kasan_poison(mem, mm_malloc_size(mem)); - if (mm_takesemaphore(heap) == false) { - kasan_unpoison(mem, mm_malloc_size(mem)); - /* Meet -ESRCH return, which means we are in situations * during context switching(See mm_takesemaphore() & getpid()). * Then add to the delay list. @@ -99,6 +95,8 @@ void mm_free(FAR struct mm_heap_s *heap, FAR void *mem) return; } + kasan_poison(mem, mm_malloc_size(mem)); + DEBUGASSERT(mm_heapmember(heap, mem)); /* Map the memory chunk into a free node */ @@ -175,5 +173,6 @@ void mm_free(FAR struct mm_heap_s *heap, FAR void *mem) /* Add the merged node to the nodelist */ mm_addfreechunk(heap, node); + mm_givesemaphore(heap); }