32 lines · cpp
1// RUN: %clangxx_lsan -O2 %s --std=c++14 -o %t && %run %t2 3#include <atomic>4#include <memory>5#include <sanitizer/lsan_interface.h>6#include <thread>7#include <vector>8 9std::atomic<bool> done;10 11void foo() {12 std::unique_ptr<char[]> mem;13 14 while (!done)15 mem.reset(new char[1000000]);16}17 18int main() {19 std::vector<std::thread> threads;20 for (int i = 0; i < 10; ++i)21 threads.emplace_back(foo);22 23 for (int i = 0; i < 100; ++i)24 __lsan_do_recoverable_leak_check();25 26 done = true;27 for (auto &t : threads)28 t.join();29 30 return 0;31}32