2013-05-14 23:48:54 +08:00
|
|
|
================
|
|
|
|
LeakSanitizer
|
|
|
|
================
|
|
|
|
|
|
|
|
.. contents::
|
|
|
|
:local:
|
|
|
|
|
|
|
|
Introduction
|
|
|
|
============
|
|
|
|
|
2013-12-11 04:10:30 +08:00
|
|
|
LeakSanitizer is a run-time memory leak detector. It can be combined with
|
2016-01-22 09:35:45 +08:00
|
|
|
: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
|
|
|
|
=====
|
|
|
|
|
[Docs] Modernize references to macOS
Summary:
This updates all places in documentation that refer to "Mac OS X", "OS X", etc.
to instead use the modern name "macOS" when no specific version number is
mentioned.
If a specific version is mentioned, this attempts to use the OS name at the time
of that version:
* Mac OS X for 10.0 - 10.7
* OS X for 10.8 - 10.11
* macOS for 10.12 - present
Reviewers: JDevlieghere
Subscribers: mgorny, christof, arphaman, cfe-commits, lldb-commits, libcxx-commits, llvm-commits
Tags: #clang, #lldb, #libc, #llvm
Differential Revision: https://reviews.llvm.org/D62654
llvm-svn: 362113
2019-05-31 00:46:22 +08:00
|
|
|
LeakSanitizer is supported on x86\_64 Linux and macOS. In order to use it,
|
2016-01-22 09:35:45 +08:00
|
|
|
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;
|
|
|
|
}
|
2017-09-14 03:40:10 +08:00
|
|
|
% clang -fsanitize=address -g memory-leak.c ; ASAN_OPTIONS=detect_leaks=1 ./a.out
|
2016-01-22 09:35:45 +08:00
|
|
|
==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.
|
2013-05-14 23:48:54 +08:00
|
|
|
|
|
|
|
More Information
|
|
|
|
================
|
|
|
|
|
2015-12-04 08:38:13 +08:00
|
|
|
`<https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer>`_
|