Questions tagged [leak-sanitizer]

LeakSanitizer (LSan) is a memory leak detector for GCC and Clang.

LeakSanitizer (LSan) is a run-time memory leak detector, available since Clang 3.4 and GCC 4.9. It is automatically enabled with AddressSanitizer (ASAN), but can also operate independently.

Once enabled at compile time using the -fsanitize=address or -fsanitize=leak, it will automatically be enabled at runtime. To disable that, use LSAN_OPTIONS=detect_leaks=0.

See also:

26 questions
29
votes
2 answers

What is the difference between a direct and indirect leak?

I got the following output from the LeakSanitizer tool. What is the difference between a direct and indirect leak, as the tool understands it? 13: ==29107==ERROR: LeakSanitizer: detected memory leaks 13: 13: Direct leak of 288 byte(s) in 6…
user7610
  • 25,267
  • 15
  • 124
  • 150
21
votes
1 answer

How to suppress LeakSanitizer report when running under -fsanitize=address?

When I compile my C++ code with -fsanitize=address, my software prints out a list of leaks at the time it exits. Is there a way to avoid the leaks report (I'm only interested in memory corruptions, not leaks)? I went to the page with ASAN flags…
Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
10
votes
3 answers

How can I see memory leaks on MacOS Big Sur using CLion?

I don't know how can I see memory leaks using CLion on MacOS Big Sur using CLion and I've tried these things: Valgrind - which is not compatible with Big Sur Leak Sanitizer from Clang - which apparently isn't compatible with MacOS according to a…
Stefan
  • 101
  • 1
  • 3
7
votes
1 answer

what are the valid sanitizer suppression strings for gcc?

When using sanitizers with gcc one can provide a list of exceptions/suppressions to deal with false positives and such. the suppression file format is poorly documented. Each suppression is of the form name_of_check:path_or_name What are the valid…
5
votes
1 answer

Only Indirect leaks and no Direct ones

After reading through this StackOverflow question: What is the difference between a direct and indirect leak? I was left with the impression that if I fix all Direct Leaks (multiple fix-test passes since an indirect leak may become a direct one…
onqtam
  • 4,356
  • 2
  • 28
  • 50
5
votes
2 answers

Runtime check for LeakSanitizer (detect_leaks=1)

I have an issue where any Leak Sanitizer backtraces that go through dynamically loaded libraries report Unknown Module for any function calls within that library. Direct leak of 48 byte(s) in 1 object(s) allocated from: #0 0x4e3e36 in malloc…
Arran Cudbard-Bell
  • 5,912
  • 2
  • 26
  • 48
5
votes
2 answers

How can I know if Leak Sanitizer is enabled at compile time?

The GCC and Clang compilers both have support for LeakSanitizer which helps finding memory leaks in C programs. Sometimes a memory leak is unavoidable (because it is being tested in a test suite for example). Such memory can be annotated using the…
Lekensteyn
  • 64,486
  • 22
  • 159
  • 192
3
votes
0 answers

Clang++ LSAN and UBSAN causes undefined reference to `__ubsan_handle_add_overflow'

When I was playing with compiler sanitizers, I was confused by this linking error when only LSAN and UBSAN are enabled on clang++. Note that the linking problem disappeared when I removed -fsanitize=leak or added these flags together:…
jerryc05
  • 454
  • 1
  • 4
  • 16
3
votes
1 answer

How to enable LSAN detect memory leaks at runtime, and not wait until the end of the process

I have an ASAN instrumented 'deamon' process that always runs in my system. I see the memory leaks are reported only when the process exits. Is there anyway that i can ask LSAN to dump the leak reports without having to kill the process ? Is there…
subbu147
  • 346
  • 1
  • 9
2
votes
0 answers

What causes the leak sanitizer to behave differently for T* and T*& in my struct implementation?

why -fsanitize=address,leak behaves differently for T* and T*&? I created a struct for pointer_ownership template struct pointer_ownership { T* ptr; bool is_owner; pointer_ownership(T*& t_ptr, bool t_is_owner) :…
kush_1244
  • 39
  • 3
2
votes
1 answer

How to use clang's LeakSanitizer on MacOS?

I'm macOS Big Sur. AFAIK, Valgrind doesn't support this OS yet. At least I've tried this. After some Googling, I switched to LeakSanitizier and tested this C code: #include void *p; int main() { p = malloc(7); p = 0; // The memory is…
anta40
  • 6,511
  • 7
  • 46
  • 73
2
votes
2 answers

What scratch buffer means in glibc?

I found that below codes makes heap leak if I check it with tcmalloc heap checker with draconian mode but the leak is not found with LSan (I assume that internal allocation in glibc is suppressed in LSan) #include #include…
hyuk myeong
  • 197
  • 1
  • 13
2
votes
1 answer

Leak/Address sanitizer in a shared library without LD_PRELOAD

I'm looking to use Clang's leak/address sanitizer on my shared library, which is loaded from JVM or dotnet (Linux) at runtime, so I can't recompile the binary. Using LD_PRELOAD makes for a very noisy output, a lot (presumably false positive?) leaks…
Błażej Czapp
  • 2,478
  • 2
  • 24
  • 18
2
votes
0 answers

LeakSanitizer finds leak in simple MPI program

This simple program leaks memory according to LeakSanitizer. #include int main(int argc, char *argv[]) { MPI_Init(&argc, &argv); MPI_Finalize(); return 0; } I am linking it to Open MPI v1.10.2. This other question asks almost…
toliveira
  • 1,533
  • 16
  • 27
2
votes
1 answer

Understanding LeakSanitizer outputs

I use AddressSanitizer from g++ on my program, and there are some outputs I have troubles understanding and acting on. I was using g++-4.8.4 before, and I'm pretty sure there was no leak reports, but I recently switched to g++-5.2.1 and now I have…
Leherenn
  • 520
  • 5
  • 16
1
2