Skip to content
mhahnFr edited this page Oct 12, 2023 · 16 revisions

Here you can find all information about the LeakSanitizer as well as the documentation of the source code.

The features

  • Sending a SIGUSR1 prints statistics of the current memory usage.
  • Sending a SIGUSR2 prints a callstack where the signal has been received.
  • More about signal handlers here.

Statistics

The statistic can be queried inside your program, refer to the documentation of lsan_stats.h.

Example:

#include <lsan_stats.h>

int main() {
    void * pointer = malloc(150);
    
    __lsan_printStats();
    
    __lsan_printFragmentationStats();
}

Adjustments

The warnings and errors displayed by this library can also be adjusted, refer to the documentation of lsan_internals.h.

The values inside that header should be adjusted directly after startup of the program.

Example:

#include <lsan_internals.h>

int main() {
    __lsan_leakCount = 50;
}

Invalid frees

The LeakSanitizer can also help to find invalid frees.

To do so, enable the __lsan_invalidFree and disable the __lsan_invalidCrash:

#include <lsan_internals.h>

int main() {
    __lsan_invalidFree  = true;
    __lsan_invalidCrash = false;
}
Clone this wiki locally