-
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.
Update the main thread's os_id on every pthread_create, and before initiating leak checking. This ensures that we have the correct os_id even if we have forked after Init(). llvm-svn: 185815
- Loading branch information
Showing
10 changed files
with
99 additions
and
2 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
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,24 @@ | ||
// Test that thread local data is handled correctly after forking without exec(). | ||
// RUN: %clangxx_lsan %s -o %t | ||
// RUN: %t 2>&1 | ||
|
||
#include <assert.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <sys/wait.h> | ||
#include <unistd.h> | ||
|
||
__thread void *thread_local_var; | ||
|
||
int main() { | ||
int status = 0; | ||
thread_local_var = malloc(1337); | ||
pid_t pid = fork(); | ||
assert(pid >= 0); | ||
if (pid > 0) { | ||
waitpid(pid, &status, 0); | ||
assert(WIFEXITED(status)); | ||
return WEXITSTATUS(status); | ||
} | ||
return 0; | ||
} |
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,44 @@ | ||
// Test that thread local data is handled correctly after forking without | ||
// exec(). In this test leak checking is initiated from a non-main thread. | ||
// RUN: %clangxx_lsan %s -o %t | ||
// RUN: %t 2>&1 | ||
|
||
#include <assert.h> | ||
#include <pthread.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <sys/wait.h> | ||
#include <unistd.h> | ||
|
||
__thread void *thread_local_var; | ||
|
||
void *exit_thread_func(void *arg) { | ||
exit(0); | ||
} | ||
|
||
void ExitFromThread() { | ||
pthread_t tid; | ||
int res; | ||
res = pthread_create(&tid, 0, exit_thread_func, 0); | ||
assert(res == 0); | ||
res = pthread_join(tid, 0); | ||
assert(res == 0); | ||
} | ||
|
||
int main() { | ||
int status = 0; | ||
thread_local_var = malloc(1337); | ||
pid_t pid = fork(); | ||
assert(pid >= 0); | ||
if (pid > 0) { | ||
waitpid(pid, &status, 0); | ||
assert(WIFEXITED(status)); | ||
return WEXITSTATUS(status); | ||
} else { | ||
// Spawn a thread and call exit() from there, to check that we track main | ||
// thread's pid correctly even if leak checking is initiated from another | ||
// thread. | ||
ExitFromThread(); | ||
} | ||
return 0; | ||
} |
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
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
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