Created
May 12, 2019 23:46
-
-
Save matutter/7fd63ca6b1a8aed28f38957309b5cdfc to your computer and use it in GitHub Desktop.
Small program demonstrates use of ASan for detecting leaks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <stdlib.h> | |
| #include <sanitizer/lsan_interface.h> | |
| /** | |
| * clang++ -g -fsanitize=address asantest.cpp | |
| * ASAN_OPTIONS=detect_leaks=1 ./a.out | |
| * | |
| * ASAN_OPTIONS=symbolize=1 ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer | |
| * ./a.out | |
| */ | |
| class Test1 { | |
| public: | |
| int i; | |
| Test1(int i) : i(i) {} | |
| ~Test1() { | |
| std::cout << "~Test1()" << std::endl; | |
| } | |
| }; | |
| #define NOINLINE __attribute__((noinline)) | |
| void run() { | |
| Test1* t = new Test1(123); | |
| t = nullptr; | |
| //void* mem = malloc(300); | |
| //mem = 0; | |
| std::cout << "Leaving run() ..." << std::endl; | |
| }; | |
| int main(int argc, char **argv) { | |
| std::cout << "Running..." << std::endl; | |
| int stack_array[100]; | |
| stack_array[1] = 0; | |
| int val = 0; //stack_array[argc + 100]; | |
| run(); | |
| __lsan_do_leak_check(); | |
| return val; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment