11 LeakSanitizer is a run-time memory leak detector. It can be combined with
12 :doc:`AddressSanitizer` to get both memory error and leak detection, or
13 used in a stand-alone mode. LSan adds almost no performance overhead
14 until the very end of the process, at which point there is an extra leak
20 :doc:`AddressSanitizer`: integrates LeakSanitizer and enables it by default on
23 .. code-block:: console
30 p = 0; // The memory is leaked here.
33 % clang -fsanitize=address -g memory-leak.c ; ASAN_OPTIONS=detect_leaks=1 ./a.out
34 ==23646==ERROR: LeakSanitizer: detected memory leaks
35 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:3
37 #1 0x4da26a in main memory-leak.c:4:7
38 #2 0x7f076fd9cec4 in __libc_start_main libc-start.c:287
39 SUMMARY: AddressSanitizer: 7 byte(s) leaked in 1 allocation(s).
41 To use LeakSanitizer in stand-alone mode, link your program with
42 ``-fsanitize=leak`` flag. Make sure to use ``clang`` (not ``ld``) for the
43 link step, so that it would link in proper LeakSanitizer run-time library
44 into the final executable.
46 Security Considerations
47 =======================
49 LeakSanitizer is a bug detection tool and its runtime is not meant to be
50 linked against production executables. While it may be useful for testing,
51 LeakSanitizer's runtime was not developed with security-sensitive
52 constraints in mind and may compromise the security of the resulting executable.
66 `<https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer>`_