brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · ecdb87f Raw
67 lines · plain
1================2LeakSanitizer3================4 5.. contents::6   :local:7 8Introduction9============10 11LeakSanitizer is a run-time memory leak detector. It can be combined with12:doc:`AddressSanitizer` to get both memory error and leak detection, or13used in a stand-alone mode. LSan adds almost no performance overhead14until the very end of the process, at which point there is an extra leak15detection phase.16 17Usage18=====19 20:doc:`AddressSanitizer`: integrates LeakSanitizer and enables it by default on21supported platforms.22 23.. code-block:: console24 25    $ cat memory-leak.c26    #include <stdlib.h>27    void *p;28    int main() {29      p = malloc(7);30      p = 0; // The memory is leaked here.31      return 0;32    }33    % clang -fsanitize=address -g memory-leak.c ; ASAN_OPTIONS=detect_leaks=1 ./a.out34    ==23646==ERROR: LeakSanitizer: detected memory leaks35    Direct leak of 7 byte(s) in 1 object(s) allocated from:36        #0 0x4af01b in __interceptor_malloc /projects/compiler-rt/lib/asan/asan_malloc_linux.cc:52:337        #1 0x4da26a in main memory-leak.c:4:738        #2 0x7f076fd9cec4 in __libc_start_main libc-start.c:28739    SUMMARY: AddressSanitizer: 7 byte(s) leaked in 1 allocation(s).40 41To use LeakSanitizer in stand-alone mode, link your program with42``-fsanitize=leak`` flag. Make sure to use ``clang`` (not ``ld``) for the43link step, so that it would link in proper LeakSanitizer run-time library44into the final executable.45 46Security Considerations47=======================48 49LeakSanitizer is a bug detection tool and its runtime is not meant to be50linked against production executables. While it may be useful for testing,51LeakSanitizer's runtime was not developed with security-sensitive52constraints in mind and may compromise the security of the resulting executable.53 54Supported Platforms55===================56 57* Android58* Fuchsia59* Linux60* macOS61* NetBSD62 63More Information64================65 66`<https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer>`_67