[lsan] Check that leak sanitizer works in the forked process
authorVitaly Buka <vitalybuka@google.com>
Mon, 27 Aug 2018 19:15:05 +0000 (19:15 +0000)
committerVitaly Buka <vitalybuka@google.com>
Mon, 27 Aug 2018 19:15:05 +0000 (19:15 +0000)
Regression test for PR38698

llvm-svn: 340769

compiler-rt/test/lsan/TestCases/Linux/fork_and_leak.cc [new file with mode: 0644]

diff --git a/compiler-rt/test/lsan/TestCases/Linux/fork_and_leak.cc b/compiler-rt/test/lsan/TestCases/Linux/fork_and_leak.cc
new file mode 100644 (file)
index 0000000..d7427ce
--- /dev/null
@@ -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;
+}
+