[compiler-rt] enable_unmalloced_free_check (PR #139125)

Jake Egan via llvm-commits llvm-commits at lists.llvm.org
Thu May 8 11:41:27 PDT 2025


https://github.com/jakeegan created https://github.com/llvm/llvm-project/pull/139125

None

>From d3ef61e69322f48d1b66b04183cc32d7896cbfed Mon Sep 17 00:00:00 2001
From: Jake Egan <jake.egan at ibm.com>
Date: Thu, 8 May 2025 14:40:52 -0400
Subject: [PATCH] enable_unmalloced_free_check

---
 compiler-rt/lib/asan/asan_allocator.cpp              | 6 ++++--
 compiler-rt/lib/sanitizer_common/sanitizer_flags.inc | 3 +++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/compiler-rt/lib/asan/asan_allocator.cpp b/compiler-rt/lib/asan/asan_allocator.cpp
index 3a55c2af65653..3208d9feb6212 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..4b4460d93388d 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.")



More information about the llvm-commits mailing list