[compiler-rt] [lsan] Fix free(NULL) interception during initialization (PR #106912)

via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 1 09:28:32 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: None (tmiasko)

<details>
<summary>Changes</summary>

Previously an attempt to free a null pointer during initialization would fail on ENSURE_LSAN_INITED assertion (since a null pointer is not owned by DlsymAlloc).

---
Full diff: https://github.com/llvm/llvm-project/pull/106912.diff


1 Files Affected:

- (modified) compiler-rt/lib/lsan/lsan_interceptors.cpp (+2) 


``````````diff
diff --git a/compiler-rt/lib/lsan/lsan_interceptors.cpp b/compiler-rt/lib/lsan/lsan_interceptors.cpp
index b569c337e97641..db27be7d06995f 100644
--- a/compiler-rt/lib/lsan/lsan_interceptors.cpp
+++ b/compiler-rt/lib/lsan/lsan_interceptors.cpp
@@ -77,6 +77,8 @@ INTERCEPTOR(void*, malloc, uptr size) {
 }
 
 INTERCEPTOR(void, free, void *p) {
+  if (!p)
+    return;
   if (DlsymAlloc::PointerIsMine(p))
     return DlsymAlloc::Free(p);
   ENSURE_LSAN_INITED;

``````````

</details>


https://github.com/llvm/llvm-project/pull/106912


More information about the llvm-commits mailing list