Skip to content

Commit dbece8e

Browse files
authored
[rtsan][NFC] Put in comment describing why freeing a nullptr is safe (llvm#113720)
Just documenting this for future devs. Also moved to `nullptr` and deleted unnecessary braces as per the coding standard.
1 parent d67f2bd commit dbece8e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,12 @@ INTERCEPTOR(void, free, void *ptr) {
431431
if (DlsymAlloc::PointerIsMine(ptr))
432432
return DlsymAlloc::Free(ptr);
433433

434-
if (ptr != NULL) {
434+
// According to the C and C++ standard, freeing a nullptr is guaranteed to be
435+
// a no-op (and thus real-time safe). This can be confirmed for looking at
436+
// __libc_free in the glibc source.
437+
if (ptr != nullptr)
435438
__rtsan_notify_intercepted_call("free");
436-
}
439+
437440
return REAL(free)(ptr);
438441
}
439442

0 commit comments

Comments
 (0)