From 81f4587dffd8f4ee6785e070d20de8709fe6361a Mon Sep 17 00:00:00 2001 From: Chris Apple Date: Fri, 25 Oct 2024 11:19:26 -0700 Subject: [PATCH] [rtsan][NFC] Put in comment describing why freeing a nullptr is safe --- compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp index 890d6c11c4076..a65871b17da5a 100644 --- a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp +++ b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp @@ -431,9 +431,12 @@ INTERCEPTOR(void, free, void *ptr) { if (DlsymAlloc::PointerIsMine(ptr)) return DlsymAlloc::Free(ptr); - if (ptr != NULL) { + // According to the C and C++ standard, freeing a nullptr is guaranteed to be + // a no-op (and thus real-time safe). This can be confirmed for looking at + // __libc_free in the glibc source. + if (ptr != nullptr) __rtsan_notify_intercepted_call("free"); - } + return REAL(free)(ptr); }