News for hackers. Stuff that matters.
Re:System memory allocator free operation zeroes out dealloc... by pjscott on Thursday September 22, 2022 @02:56PM (#32943131)
I urge anybody using a C family language to become familiar with AddressSanitizer [1], a tool that (with support from the compiler) detects an impressive variety of memory bugs at runtime. The scenario you describe would result in the program immediately crashing with a read-after-free error, along with stack traces for the most recent calls to malloc and free that involved that address. It's remarkably useful and straightforward, and Apple's tooling has good support for it, along with Xcode integration [2].

[1] https://clang.llvm.org/docs/AddressSanitizer.html

[2] https://developer.apple.com/documentation/xcode/diagnosing-m...

Re:System memory allocator free operation zeroes out dealloc... by dlundqvist on Thursday September 22, 2022 @03:28PM (#32943553)
This. I personally think ASAN and it's friends are some of, if not the, best things to happen to C/C++ in the last decade. We use it at work, I use it in all my personal projects. We've found "countless" bugs with ASAN together with LSAN.

It should be part any project from the start, run as much as possible with ASAN when the performance hit can be afforded.

Re:System memory allocator free operation zeroes out dealloc... by pseudoramble on Thursday September 22, 2022 @05:52PM (#32945098)
Just confirming, but you're taking about Leak Sanitizer? https://clang.llvm.org/docs/LeakSanitizer.html. Not really familiar with these tools, definitely not the acronyms.
Re:System memory allocator free operation zeroes out dealloc... by dlundqvist on Thursday September 22, 2022 @05:59PM (#32945172)
Sorry, yes, I meant Leak Sanitizer.
Re:System memory allocator free operation zeroes out dealloc... by pseudoramble on Thursday September 22, 2022 @06:06PM (#32945241)
No need to be sorry! I appreciate it!

It was actually in the link the parent posted. I just missed it at first.

Re:System memory allocator free operation zeroes out dealloc... by thewebcount on Thursday September 22, 2022 @07:52PM (#32946158)
Agreed! Likewise, if you're doing anything multithreaded, ThreadSanitizer (TSAN) is a must!
Re:System memory allocator free operation zeroes out dealloc... by rock_artist on Thursday September 22, 2022 @04:01PM (#32943916)
I’m using sanitizers on macOS for few years now. Doing cross-platform, ~~it really feels inferior~~ I really miss them on MSVC side. (wrt to exclusive asan since VS2019)

Still, in some cases you have some tiny uninitialized member for example that is much harder to find. So with this malloc it might even cover those more.