diff --git a/pc/BUILD.gn b/pc/BUILD.gn index faa2b1dda6..b071145c94 100644 --- a/pc/BUILD.gn +++ b/pc/BUILD.gn @@ -1063,6 +1063,7 @@ rtc_source_set("rtc_stats_collector") { "../rtc_base:stringutils", "../rtc_base:threading", "../rtc_base:timeutils", + "../rtc_base/containers:flat_set", "../rtc_base/synchronization:mutex", ] absl_deps = [ diff --git a/pc/rtc_stats_collector.cc b/pc/rtc_stats_collector.cc index e443b15c9c..8a7839a95c 100644 --- a/pc/rtc_stats_collector.cc +++ b/pc/rtc_stats_collector.cc @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -2496,16 +2497,13 @@ void RTCStatsCollector::OnSctpDataChannelStateChanged( DataChannelInterface::DataState state) { RTC_DCHECK_RUN_ON(signaling_thread_); if (state == DataChannelInterface::DataState::kOpen) { - bool result = internal_record_.opened_data_channels - .insert(reinterpret_cast(channel)) - .second; + bool result = internal_record_.opened_data_channels.insert(channel).second; RTC_DCHECK(result); ++internal_record_.data_channels_opened; } else if (state == DataChannelInterface::DataState::kClosed) { // Only channels that have been fully opened (and have increased the // `data_channels_opened_` counter) increase the closed counter. - if (internal_record_.opened_data_channels.erase( - reinterpret_cast(channel))) { + if (internal_record_.opened_data_channels.erase(channel)) { ++internal_record_.data_channels_closed; } } diff --git a/pc/rtc_stats_collector.h b/pc/rtc_stats_collector.h index 6c36d22248..20df528774 100644 --- a/pc/rtc_stats_collector.h +++ b/pc/rtc_stats_collector.h @@ -16,7 +16,6 @@ #include #include #include -#include #include #include @@ -39,6 +38,7 @@ #include "pc/track_media_info_map.h" #include "pc/transport_stats.h" #include "rtc_base/checks.h" +#include "rtc_base/containers/flat_set.h" #include "rtc_base/event.h" #include "rtc_base/ref_count.h" #include "rtc_base/ssl_certificate.h" @@ -323,7 +323,10 @@ class RTCStatsCollector : public rtc::RefCountInterface { uint32_t data_channels_closed; // Identifies by address channels that have been opened, which remain in the // set until they have been fully closed. - std::set opened_data_channels; + // NOTE: There is no reference held here or any other type of guarantee that + // these pointers remain valid. So they MUST NOT be followed; hence, void* + // is used and not the explicit type. + webrtc::flat_set opened_data_channels; }; InternalRecord internal_record_; };