diff options
Diffstat (limited to 'test/lsan/TestCases/Linux/fork_and_leak.cc')
-rw-r--r-- | test/lsan/TestCases/Linux/fork_and_leak.cc | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/lsan/TestCases/Linux/fork_and_leak.cc b/test/lsan/TestCases/Linux/fork_and_leak.cc new file mode 100644 index 000000000000..d7427ce3ed04 --- /dev/null +++ b/test/lsan/TestCases/Linux/fork_and_leak.cc @@ -0,0 +1,23 @@ +// Test that leaks detected after forking without exec(). +// RUN: %clangxx_lsan %s -o %t && not %run %t 2>&1 | FileCheck %s + +#include <assert.h> +#include <stdlib.h> +#include <sys/wait.h> +#include <unistd.h> + +int main() { + pid_t pid = fork(); + assert(pid >= 0); + if (pid > 0) { + int status = 0; + waitpid(pid, &status, 0); + assert(WIFEXITED(status)); + return WEXITSTATUS(status); + } else { + malloc(1337); + // CHECK: LeakSanitizer: detected memory leaks + } + return 0; +} + |