Skip to content

Commit

Permalink
[test][sanitizer] Convert test from C++ to C
Browse files Browse the repository at this point in the history
This avoids internal libstdc++ leaks.
  • Loading branch information
vitalybuka committed Dec 13, 2023
1 parent 215c565 commit 0efc167
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %clangxx -O0 %s -o %t && %env_tool_opts=die_after_fork=0 %run %t
// RUN: %clang -O0 %s -o %t && %env_tool_opts=die_after_fork=0 %run %t

// UNSUPPORTED: asan, lsan, hwasan

Expand Down Expand Up @@ -28,10 +28,11 @@ pthread_barrier_t bar;
// start with locked internal mutexes.
void ShouldNotDeadlock() {
// Don't bother with leaks, we try to trigger allocator or lsan deadlock.
__lsan::ScopedDisabler disable;
char *volatile p = new char[10];
__lsan_disable();
void *volatile p = malloc(10);
__lsan_do_recoverable_leak_check();
delete[] p;
free(p);
__lsan_enable();
}

// Prevent stack buffer cleanup by instrumentation.
Expand Down Expand Up @@ -59,7 +60,7 @@ NOSAN static void *inchild(void *arg) {
int main(void) {
pid_t pid;

pthread_barrier_init(&bar, nullptr, 2);
pthread_barrier_init(&bar, NULL, 2);
pthread_t thread_id;
while (pthread_create(&thread_id, 0, &inparent, 0) != 0) {
}
Expand Down

0 comments on commit 0efc167

Please sign in to comment.