Skip to content

Commit 6341c97

Browse files
Cherry pick PR #7110: starboard: Check pthread_join completes successfully (#7120)
Refer to the original PR: #7110 The code relies on a fundamental invariant: after pthread_join() returns, the joined thread is guaranteed to have terminated. This means no more callbacks will be made from that thread. A failure in `pthread_join()` breaches this invariant and leads to an unexpected state where the supposedly-completed thread is still running and calling callbacks. This can lead to use-after-free errors or other race conditions. This change adds a check to enforce this invariant, preventing the application from continuing in a corrupt state. #vibe-coded Bug: 443334872 --------- Co-authored-by: Kyujung Youn <kjyoun@google.com>
1 parent c07c765 commit 6341c97

File tree

6 files changed

+6
-6
lines changed

6 files changed

+6
-6
lines changed

starboard/android/shared/audio_track_audio_sink_type.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ AudioTrackAudioSink::~AudioTrackAudioSink() {
173173
quit_ = true;
174174

175175
if (audio_out_thread_ != 0) {
176-
pthread_join(audio_out_thread_, NULL);
176+
SB_CHECK_EQ(pthread_join(audio_out_thread_, nullptr), 0);
177177
}
178178
}
179179

starboard/android/shared/continuous_audio_track_sink.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ ContinuousAudioTrackSink::~ContinuousAudioTrackSink() {
103103
quit_ = true;
104104

105105
if (audio_out_thread_ != 0) {
106-
pthread_join(audio_out_thread_, NULL);
106+
SB_CHECK_EQ(pthread_join(audio_out_thread_, nullptr), 0);
107107
}
108108
}
109109

starboard/android/shared/media_decoder.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ void MediaDecoder::TerminateDecoderThread() {
394394
}
395395

396396
if (decoder_thread_ != 0) {
397-
pthread_join(decoder_thread_, nullptr);
397+
SB_CHECK_EQ(pthread_join(decoder_thread_, nullptr), 0);
398398
decoder_thread_ = 0;
399399
}
400400
}

starboard/shared/starboard/audio_sink/stub_audio_sink_type.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ StubAudioSink::~StubAudioSink() {
8282
ScopedLock lock(mutex_);
8383
destroying_ = true;
8484
}
85-
pthread_join(audio_out_thread_, NULL);
85+
SB_CHECK_EQ(pthread_join(audio_out_thread_, nullptr), 0);
8686
}
8787

8888
// static

starboard/shared/starboard/player/filter/punchout_video_renderer_sink.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ PunchoutVideoRendererSink::PunchoutVideoRendererSink(SbPlayer player,
4242
PunchoutVideoRendererSink::~PunchoutVideoRendererSink() {
4343
if (thread_ != 0) {
4444
stop_requested_.store(true);
45-
pthread_join(thread_, NULL);
45+
SB_CHECK_EQ(pthread_join(thread_, nullptr), 0);
4646
}
4747
}
4848

starboard/shared/starboard/player/player_worker.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ PlayerWorker::~PlayerWorker() {
9191

9292
if (thread_ != 0) {
9393
job_queue_->Schedule(std::bind(&PlayerWorker::DoStop, this));
94-
pthread_join(thread_, NULL);
94+
SB_CHECK_EQ(pthread_join(thread_, nullptr), 0);
9595
thread_ = 0;
9696

9797
// Now the whole pipeline has been torn down and no callback will be called.

0 commit comments

Comments
 (0)