1 // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
3 // Use of gethostent provokes caching of some resources inside of libc.
4 // They are freed in __libc_thread_freeres very late in thread lifetime,
5 // after our ThreadFinish. __libc_thread_freeres calls free which
6 // previously crashed in malloc hooks.
13 extern "C" void __sanitizer_malloc_hook(void *ptr
, size_t size
) {
14 __atomic_fetch_add(&X
, 1, __ATOMIC_RELAXED
);
17 extern "C" void __sanitizer_free_hook(void *ptr
) {
18 __atomic_fetch_sub(&X
, 1, __ATOMIC_RELAXED
);
21 void *Thread(void *x
) {
23 gethostbyname("llvm.org");
31 pthread_create(&th
, NULL
, Thread
, NULL
);
32 pthread_join(th
, NULL
);
33 fprintf(stderr
, "DONE\n");