From 338602596cab95d90137409ab1d9ca462c859156 Mon Sep 17 00:00:00 2001 From: terelius Date: Fri, 12 May 2017 23:37:18 -0700 Subject: [PATCH] Initialize PeerConnection members in declaration order and destroy them in reverse order. BUG=webrtc:7658 Review-Url: https://codereview.webrtc.org/2882803002 Cr-Commit-Position: refs/heads/master@{#18130} --- webrtc/pc/peerconnection.cc | 6 ++++-- webrtc/pc/peerconnection.h | 15 +++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/webrtc/pc/peerconnection.cc b/webrtc/pc/peerconnection.cc index 65203fdc73..852dd39de5 100644 --- a/webrtc/pc/peerconnection.cc +++ b/webrtc/pc/peerconnection.cc @@ -395,10 +395,10 @@ PeerConnection::PeerConnection(PeerConnectionFactory* factory) : factory_(factory), observer_(NULL), uma_observer_(NULL), + event_log_(RtcEventLog::Create()), signaling_state_(kStable), ice_connection_state_(kIceConnectionNew), ice_gathering_state_(kIceGatheringNew), - event_log_(RtcEventLog::Create()), rtcp_cname_(GenerateRtcpCname()), local_streams_(StreamCollection::Create()), remote_streams_(StreamCollection::Create()) {} @@ -1289,7 +1289,6 @@ void PeerConnection::Close() { stats_->UpdateStats(kStatsOutputLevelStandard); session_->Close(); - event_log_.reset(); network_thread()->Invoke( RTC_FROM_HERE, rtc::Bind(&cricket::PortAllocator::DiscardCandidatePool, @@ -1297,6 +1296,9 @@ void PeerConnection::Close() { factory_->worker_thread()->Invoke(RTC_FROM_HERE, [this] { call_.reset(); }); + + // The event log must outlive call (and any other object that uses it). + event_log_.reset(); } void PeerConnection::OnSessionStateChange(WebRtcSession* /*session*/, diff --git a/webrtc/pc/peerconnection.h b/webrtc/pc/peerconnection.h index 23e7e8e58b..1e2ca3bb95 100644 --- a/webrtc/pc/peerconnection.h +++ b/webrtc/pc/peerconnection.h @@ -402,14 +402,16 @@ class PeerConnection : public PeerConnectionInterface, rtc::scoped_refptr factory_; PeerConnectionObserver* observer_; UMAObserver* uma_observer_; + + // The EventLog needs to outlive |call_| (and any other object that uses it). + std::unique_ptr event_log_; + SignalingState signaling_state_; IceConnectionState ice_connection_state_; IceGatheringState ice_gathering_state_; PeerConnectionInterface::RTCConfiguration configuration_; std::unique_ptr port_allocator_; - // The EventLog needs to outlive |call_|. - std::unique_ptr event_log_; // One PeerConnection has only one RTCP CNAME. // https://tools.ietf.org/html/draft-ietf-rtcweb-rtp-usage-26#section-4.9 @@ -436,15 +438,16 @@ class PeerConnection : public PeerConnectionInterface, bool remote_peer_supports_msid_ = false; + std::unique_ptr call_; + std::unique_ptr session_; + std::unique_ptr stats_; // A pointer is passed to senders_ + rtc::scoped_refptr stats_collector_; + std::vector>> senders_; std::vector< rtc::scoped_refptr>> receivers_; - std::unique_ptr session_; - std::unique_ptr call_; - std::unique_ptr stats_; - rtc::scoped_refptr stats_collector_; }; } // namespace webrtc