File: LeakSanitizer.rst

package info (click to toggle)
llvm-toolchain-3.9 1%3A3.9.1-8
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 441,060 kB
  • ctags: 428,777
  • sloc: cpp: 2,546,577; ansic: 538,318; asm: 119,677; objc: 103,316; python: 102,148; sh: 27,847; pascal: 5,626; ml: 5,510; perl: 5,293; lisp: 4,801; makefile: 2,177; xml: 686; cs: 362; php: 212; csh: 117
file content (49 lines) | stat: -rw-r--r-- 1,545 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
================
LeakSanitizer
================

.. contents::
   :local:

Introduction
============

LeakSanitizer is a run-time memory leak detector. It can be combined with
:doc:`AddressSanitizer` to get both memory error and leak detection, or
used in a stand-alone mode. LSan adds almost no performance overhead
until the very end of the process, at which point there is an extra leak
detection phase.

Usage
=====

LeakSanitizer is only supported on x86\_64 Linux. In order to use it,
simply build your program with :doc:`AddressSanitizer`:

.. code-block:: console

    $ cat memory-leak.c
    #include <stdlib.h>
    void *p;
    int main() {
      p = malloc(7);
      p = 0; // The memory is leaked here.
      return 0;
    }
    % clang -fsanitize=address -g memory-leak.c ; ./a.out
    ==23646==ERROR: LeakSanitizer: detected memory leaks
    Direct leak of 7 byte(s) in 1 object(s) allocated from:
        #0 0x4af01b in __interceptor_malloc /projects/compiler-rt/lib/asan/asan_malloc_linux.cc:52:3
        #1 0x4da26a in main memory-leak.c:4:7
        #2 0x7f076fd9cec4 in __libc_start_main libc-start.c:287
    SUMMARY: AddressSanitizer: 7 byte(s) leaked in 1 allocation(s).

To use LeakSanitizer in stand-alone mode, link your program with
``-fsanitize=leak`` flag. Make sure to use ``clang`` (not ``ld``) for the
link step, so that it would link in proper LeakSanitizer run-time library
into the final executable.

More Information
================

`<https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer>`_