Skip to content

Commit 4bc772c

Browse files
committed
Update Leak sanitizer examples
Expand from just a direct leak, to both a direct and indirect leak example programs.
1 parent 6eb10c9 commit 4bc772c

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

example/all/CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,13 @@ endif()
6161
add_test(tsan tsanFail)
6262

6363
# Fails with LeakSanitizer
64-
add_executable(lsanFail ../src/lsan_fail.c)
65-
target_code_coverage(lsanFail AUTO ALL)
66-
add_test(lsan lsanFail)
64+
add_executable(lsan_direct_leak ../src/lsan/direct_leak.c)
65+
target_code_coverage(lsan_direct_leak AUTO ALL)
66+
add_test(lsan_direct_leak lsan_direct_leak)
67+
68+
add_executable(lsan_indirect_leak ../src/lsan/indirect_leak.c)
69+
target_code_coverage(lsan_indirect_leak AUTO ALL)
70+
add_test(lsan_indirect_leak lsan_indirect_leak)
6771

6872
# Fails with AddressSanitizer
6973
if(EXAMPLE_USE_SANITIZER STREQUAL "address")

example/src/lsan/direct_leak.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// example of a direct memory leak, where no pointer to the memory exists
2+
#include <stdlib.h>
3+
4+
int main() {
5+
void *p = malloc(7);
6+
p = 0; // failure point
7+
return 0;
8+
}

example/src/lsan/indirect_leak.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// example of an indirect memory leak, where a pointer to the memory still exists
2+
#include <stdlib.h>
3+
4+
int main() {
5+
void *p = malloc(7);
6+
return 0;
7+
} // failure point

example/src/lsan_fail.c

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)