1 // Regression test for a deadlock in leak detection,
2 // where lsan would call dl_iterate_phdr while holding the allocator lock.
3 // RUN: %clangxx_lsan %s -o %t && %run %t
13 int Callback(struct dl_phdr_info
*info
, size_t size
, void *data
) {
14 for (int step
= 0; step
< 50; ++step
) {
16 for (int i
= 0; i
< 1000; ++i
)
17 p
[i
] = malloc(10 * i
);
22 for (int i
= 0; i
< 1000; ++i
)
26 return 1; // just once
30 // This is just a fail-safe to turn a deadlock (in case the bug reappears)
31 // into a (slow) test failure.
33 if (!out
.try_lock()) {
34 write(2, "DEADLOCK\n", 9);
43 std::thread
t([] { dl_iterate_phdr(Callback
, nullptr); });
46 std::thread
w(Watchdog
);
49 // Wait for the malloc thread to preheat, then start leak detection (on exit)