Skip to content

Commit 17cbd59

Browse files
committed
Ensure all pthread_cond_t are initialized in unit tests
1 parent 12452b4 commit 17cbd59

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

compiler-rt/lib/radsan/tests/radsan_test_interceptors.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,17 +363,20 @@ TEST(TestRadsanInterceptors, SpinLockLockDiesWhenRealtime) {
363363
#endif
364364

365365
TEST(TestRadsanInterceptors, PthreadCondSignalDiesWhenRealtime) {
366-
auto Func = []() {
367-
pthread_cond_t cond{};
368-
pthread_cond_signal(&cond);
369-
};
366+
pthread_cond_t cond{};
367+
pthread_cond_init(&cond, NULL);
368+
369+
auto Func = [&cond]() { pthread_cond_signal(&cond); };
370370
expectRealtimeDeath(Func, "pthread_cond_signal");
371371
expectNonrealtimeSurvival(Func);
372+
373+
pthread_cond_destroy(&cond);
372374
}
373375

374376
TEST(TestRadsanInterceptors, PthreadCondBroadcastDiesWhenRealtime) {
375377
pthread_cond_t cond{};
376378
pthread_cond_init(&cond, NULL);
379+
377380
auto Func = [&cond]() { pthread_cond_broadcast(&cond); };
378381
expectRealtimeDeath(Func, "pthread_cond_broadcast");
379382
expectNonrealtimeSurvival(Func);
@@ -386,11 +389,15 @@ TEST(TestRadsanInterceptors, PthreadCondWaitDiesWhenRealtime) {
386389
pthread_mutex_t mutex;
387390
ASSERT_EQ(0, pthread_cond_init(&cond, nullptr));
388391
ASSERT_EQ(0, pthread_mutex_init(&mutex, nullptr));
392+
389393
auto Func = [&]() { pthread_cond_wait(&cond, &mutex); };
390394
expectRealtimeDeath(Func, "pthread_cond_wait");
391395
// It's very difficult to test the success case here without doing some
392396
// sleeping, which is at the mercy of the scheduler. What's really important
393397
// here is the interception - so we're only testing that for now.
398+
399+
pthread_cond_destroy(&cond);
400+
pthread_mutex_destroy(&mutex);
394401
}
395402

396403
TEST(TestRadsanInterceptors, PthreadRwlockRdlockDiesWhenRealtime) {

0 commit comments

Comments
 (0)