-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use of gethostent provokes caching of some resources inside of libc. They are freed in __libc_thread_freeres very late in thread lifetime, after our ThreadFinish. __libc_thread_freeres calls free which previously crashed in malloc hooks. Fix it by setting ignore_interceptors for finished threads, which in turn prevents malloc hooks. Reviewed By: melver Differential Revision: https://reviews.llvm.org/D113989
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s | ||
|
||
// Use of gethostent provokes caching of some resources inside of libc. | ||
// They are freed in __libc_thread_freeres very late in thread lifetime, | ||
// after our ThreadFinish. __libc_thread_freeres calls free which | ||
// previously crashed in malloc hooks. | ||
|
||
#include "../test.h" | ||
#include <netdb.h> | ||
|
||
long X; | ||
|
||
extern "C" void __sanitizer_malloc_hook(void *ptr, size_t size) { | ||
__atomic_fetch_add(&X, 1, __ATOMIC_RELAXED); | ||
} | ||
|
||
extern "C" void __sanitizer_free_hook(void *ptr) { | ||
__atomic_fetch_sub(&X, 1, __ATOMIC_RELAXED); | ||
} | ||
|
||
void *Thread(void *x) { | ||
sethostent(1); | ||
gethostbyname("llvm.org"); | ||
gethostent(); | ||
endhostent(); | ||
return NULL; | ||
} | ||
|
||
int main() { | ||
pthread_t th; | ||
pthread_create(&th, NULL, Thread, NULL); | ||
pthread_join(th, NULL); | ||
fprintf(stderr, "DONE\n"); | ||
return 0; | ||
} | ||
|
||
// CHECK: DONE |