Safeguard SctpDataChannel against detached controller
Since the lifetime of an SctpDataChannel is not strictly controlled
by its controller, the controller might go away before the channel
does. This CL guards against this.
Bug: webrtc:13931
Change-Id: I07046fe896d1a66bf89287429beb0587382a13a9
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/261940
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Florent Castelli <orphis@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#36852}
diff --git a/pc/data_channel_controller.cc b/pc/data_channel_controller.cc
index a9fa3da..8dde417 100644
--- a/pc/data_channel_controller.cc
+++ b/pc/data_channel_controller.cc
@@ -22,6 +22,15 @@
namespace webrtc {
+DataChannelController::~DataChannelController() {
+ // Since channels may have multiple owners, we cannot guarantee that
+ // they will be deallocated before destroying the controller.
+ // Therefore, detach them from the controller.
+ for (auto channel : sctp_data_channels_) {
+ channel->DetachFromController();
+ }
+}
+
bool DataChannelController::HasDataChannels() const {
RTC_DCHECK_RUN_ON(signaling_thread());
return !sctp_data_channels_.empty();