aboutsummaryrefslogtreecommitdiff
path: root/test/lsan/TestCases/Linux/fork_and_leak.cc
blob: d7427ce3ed04f7d44febece1d53d1ece1b4350d3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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;
}