Index: talk/app/webrtc/peerconnection.cc |
diff --git a/talk/app/webrtc/peerconnection.cc b/talk/app/webrtc/peerconnection.cc |
index 933dc83c25642278d49a9491c2818a57f74fd217..b8d5e05e158a1b72869f528ec5649e2d502c75b5 100644 |
--- a/talk/app/webrtc/peerconnection.cc |
+++ b/talk/app/webrtc/peerconnection.cc |
@@ -107,6 +107,7 @@ enum { |
MSG_SET_SESSIONDESCRIPTION_FAILED, |
MSG_CREATE_SESSIONDESCRIPTION_FAILED, |
MSG_GETSTATS, |
+ MSG_FREE_DATACHANNELS, |
}; |
struct SetSessionDescriptionMsg : public rtc::MessageData { |
@@ -1329,6 +1330,10 @@ void PeerConnection::OnMessage(rtc::Message* msg) { |
delete param; |
break; |
} |
+ case MSG_FREE_DATACHANNELS: { |
+ sctp_data_channels_to_free_.clear(); |
+ break; |
+ } |
default: |
RTC_DCHECK(false && "Not implemented"); |
break; |
@@ -1902,13 +1907,18 @@ void PeerConnection::AllocateSctpSids(rtc::SSLRole role) { |
} |
void PeerConnection::OnSctpDataChannelClosed(DataChannel* channel) { |
+ RTC_DCHECK(signaling_thread()->IsCurrent()); |
for (auto it = sctp_data_channels_.begin(); it != sctp_data_channels_.end(); |
++it) { |
if (it->get() == channel) { |
if (channel->id() >= 0) { |
sid_allocator_.ReleaseSid(channel->id()); |
} |
+ // Since this method is triggered by a signal from the DataChannel, |
+ // we can't free it directly here; we need to free it asynchronously. |
+ sctp_data_channels_to_free_.push_back(*it); |
sctp_data_channels_.erase(it); |
+ signaling_thread()->Post(this, MSG_FREE_DATACHANNELS, nullptr); |
return; |
} |
} |