introduce
Fast Memory Detector can detect the following bugs:
- Out-of-bounds access to heap memory, stack memory and global variables
- Use-after-free Memory reuse
- Use after return (use-after-return)
- Double free
Compile build
See the build guide of Clang. CMake is not supported
Method of use
You only need to add when compiling and linking the program
-faddress-sanitizer
options
For reasonable performance, add
-O1
Or higher optimization levels
For better stack tracing in error messages, add
-fno-omit-frame-pointer
options
To get a perfect stack trace, you might want to disable inline (
just use -O1
) and tail call elimination-fno-optimize-sibling-calls
__has_feature(address_sanitizer)
In some cases, depending on whether AddressSanitizer is enabled, the _has_feature can be used to do this:
#if defined(__has_feature) && __has_feature(address_sanitizer)
code that runs only under AddressSanitizer
#else
code that does not run under AddressSanitizer
#endif
Copy the code
limited
AddressSanitizer uses more real memory than a local run, depending on the size allocated
On 64-bit platforms, AddresSanitizer maps 16+ TERabytes of virtual address space, which means tools like ULimit don’t work
Static linking is not supported
Attached link address:
ASAN document