Skip to content

Commit 8b5604b

Browse files
claudeclaude
authored andcommitted
fix: guard OnStateChange against null _jingleDataChannel
OnPeerConnectionClosed() dispatches a kClosed event and calls Stop(), but the network thread can still fire OnStateChange() concurrently. If OnStateChange runs after OnPeerConnectionClosed has already called CleanupInternals (which sets _jingleDataChannel to nullptr), accessing _jingleDataChannel->state() crashes with a null pointer dereference. Remove the redundant CleanupInternals() call from OnPeerConnectionClosed (added in 33ceabf) — its purpose was to dispatch close events before PeerConnection::Close() cancels SafeTask callbacks, but HandleStateChange already does that. CleanupInternals will still run when OnStateChange receives kClosed from the network thread. Add a null guard in OnStateChange for the case where it races with OnPeerConnectionClosed during shutdown. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 826a0f8 commit 8b5604b

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/interfaces/rtc_data_channel.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,15 @@ void RTCDataChannel::CleanupInternals() {
119119

120120
void RTCDataChannel::OnPeerConnectionClosed() {
121121
if (_jingleDataChannel != nullptr) {
122-
CleanupInternals();
123122
HandleStateChange(*this, webrtc::DataChannelInterface::kClosed);
124123
Stop();
125124
}
126125
}
127126

128127
void RTCDataChannel::OnStateChange() {
128+
if (_jingleDataChannel == nullptr) {
129+
return;
130+
}
129131
auto state = _jingleDataChannel->state();
130132
if (state == webrtc::DataChannelInterface::kClosed) {
131133
CleanupInternals();

0 commit comments

Comments
 (0)