| 1 | // Test that leaks detected after forking without exec(). |
| 2 | // RUN: %clangxx_lsan %s -o %t && not %run %t 2>&1 | FileCheck %s |
| 3 | |
| 4 | /// Fails on clang-cmake-aarch64-full (glibc 2.27-3ubuntu1.4). |
| 5 | // UNSUPPORTED: target=aarch64{{.*}} |
| 6 | |
| 7 | #include <assert.h> |
| 8 | #include <stdlib.h> |
| 9 | #include <sys/wait.h> |
| 10 | #include <unistd.h> |
| 11 | |
| 12 | int main() { |
| 13 | pid_t pid = fork(); |
| 14 | assert(pid >= 0); |
| 15 | if (pid > 0) { |
| 16 | int status = 0; |
| 17 | waitpid(pid: pid, stat_loc: &status, options: 0); |
| 18 | assert(WIFEXITED(status)); |
| 19 | return WEXITSTATUS(status); |
| 20 | } else { |
| 21 | for (int i = 0; i < 10; ++i) |
| 22 | malloc(size: 1337); |
| 23 | // CHECK: LeakSanitizer: detected memory leaks |
| 24 | } |
| 25 | return 0; |
| 26 | } |
| 27 | |
| 28 | |