Skip to content

Commit

Permalink
Avoid touching channel after OnSctpDataChannelClosed
Browse files Browse the repository at this point in the history
Bug: chromium:1454086
Change-Id: I39573b706c4031d091c45a182b13cb3b2dba6233
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/309920
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#40332}
  • Loading branch information
Tommi authored and WebRTC LUCI CQ committed Jun 22, 2023
1 parent afa0f22 commit eec1810
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pc/data_channel_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,19 @@ void DataChannelController::OnChannelStateChanged(
SctpDataChannel* channel,
DataChannelInterface::DataState state) {
RTC_DCHECK_RUN_ON(network_thread());

// Stash away the internal id here in case `OnSctpDataChannelClosed` ends up
// releasing the last reference to the channel.
const int channel_id = channel->internal_id();

if (state == DataChannelInterface::DataState::kClosed)
OnSctpDataChannelClosed(channel);

DataChannelUsage channel_usage = sctp_data_channels_n_.empty()
? DataChannelUsage::kHaveBeenUsed
: DataChannelUsage::kInUse;
signaling_thread()->PostTask(SafeTask(
signaling_safety_.flag(), [this, channel_id = channel->internal_id(),
state = state, channel_usage] {
signaling_safety_.flag(), [this, channel_id, state, channel_usage] {
RTC_DCHECK_RUN_ON(signaling_thread());
channel_usage_ = channel_usage;
pc_->OnSctpDataChannelStateChanged(channel_id, state);
Expand Down

0 comments on commit eec1810

Please sign in to comment.