diff --git a/compiler-rt/lib/asan/asan_allocator.cpp b/compiler-rt/lib/asan/asan_allocator.cpp index 3a55c2af65653..8a56132bf946a 100644 --- a/compiler-rt/lib/asan/asan_allocator.cpp +++ b/compiler-rt/lib/asan/asan_allocator.cpp @@ -797,8 +797,10 @@ struct Allocator { void ReportInvalidFree(void *ptr, u8 chunk_state, BufferedStackTrace *stack) { if (chunk_state == CHUNK_QUARANTINE) ReportDoubleFree((uptr)ptr, stack); - else - ReportFreeNotMalloced((uptr)ptr, stack); + else { + if (common_flags()->enable_unmalloced_free_check) + ReportFreeNotMalloced((uptr)ptr, stack); + } } void CommitBack(AsanThreadLocalMallocStorage *ms, BufferedStackTrace *stack) { diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc b/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc index c1e3530618c20..e7d0f3a6d6496 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc @@ -282,3 +282,6 @@ COMMON_FLAG(bool, enable_symbolizer_markup, SANITIZER_FUCHSIA, COMMON_FLAG(bool, detect_invalid_join, true, "If set, check invalid joins of threads.") +COMMON_FLAG(bool, enable_unmalloced_free_check, !SANITIZER_AIX, + "if true, FreeNotMalloced error will be reported. Only disable " + "this error detecting on AIX by default for now.")