diff options
Diffstat (limited to 'chromium/third_party/blink/renderer/modules/peerconnection/rtc_peer_connection_handler.cc')
-rw-r--r-- | chromium/third_party/blink/renderer/modules/peerconnection/rtc_peer_connection_handler.cc | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/chromium/third_party/blink/renderer/modules/peerconnection/rtc_peer_connection_handler.cc b/chromium/third_party/blink/renderer/modules/peerconnection/rtc_peer_connection_handler.cc index 58168b98601..9f52fca8f30 100644 --- a/chromium/third_party/blink/renderer/modules/peerconnection/rtc_peer_connection_handler.cc +++ b/chromium/third_party/blink/renderer/modules/peerconnection/rtc_peer_connection_handler.cc @@ -713,6 +713,8 @@ class RTCPeerConnectionHandler::WebRtcSetDescriptionObserverImpl if (handler_) { handler_->OnModifySctpTransport(std::move(states.sctp_transport_state)); } + // Since OnSessionDescriptionsUpdated can fire events, it may cause + // garbage collection. Ensure that handler_ is still valid. if (handler_) { handler_->OnModifyTransceivers( states.signaling_state, std::move(states.transceiver_states), @@ -1066,6 +1068,8 @@ bool RTCPeerConnectionHandler::Initialize( CHECK(!initialize_called_); initialize_called_ = true; + // Prevent garbage collection of client_ during processing. + auto* client_on_stack = client_; peer_connection_tracker_ = PeerConnectionTracker::From(*frame); configuration_ = server_configuration; @@ -1104,8 +1108,8 @@ bool RTCPeerConnectionHandler::Initialize( peer_connection_tracker_->RegisterPeerConnection(this, configuration_, frame_); } - - return true; + // Gratuitous usage of client_on_stack to prevent compiler errors. + return !!client_on_stack; } bool RTCPeerConnectionHandler::InitializeForTest( @@ -2066,9 +2070,11 @@ void RTCPeerConnectionHandler::OnSessionDescriptionsUpdated( pending_remote_description, std::unique_ptr<webrtc::SessionDescriptionInterface> current_remote_description) { + // Prevent garbage collection of client_ during processing. + auto* client_on_stack = client_; if (!client_ || is_closed_) return; - client_->DidChangeSessionDescriptions( + client_on_stack->DidChangeSessionDescriptions( pending_local_description ? CreateWebKitSessionDescription(pending_local_description.get()) : nullptr, @@ -2294,8 +2300,12 @@ void RTCPeerConnectionHandler::OnIceCandidate(const String& sdp, int sdp_mline_index, int component, int address_family) { + // In order to ensure that the RTCPeerConnection is not garbage collected + // from under the function, we keep a pointer to it on the stack. + auto* client_on_stack = client_; DCHECK(task_runner_->RunsTasksInCurrentSequence()); TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::OnIceCandidateImpl"); + // This line can cause garbage collection. auto* platform_candidate = MakeGarbageCollected<RTCIceCandidatePlatform>( sdp, sdp_mid, sdp_mline_index); if (peer_connection_tracker_) { @@ -2315,7 +2325,7 @@ void RTCPeerConnectionHandler::OnIceCandidate(const String& sdp, } } if (!is_closed_) - client_->DidGenerateICECandidate(platform_candidate); + client_on_stack->DidGenerateICECandidate(platform_candidate); } void RTCPeerConnectionHandler::OnIceCandidateError( @@ -2327,7 +2337,6 @@ void RTCPeerConnectionHandler::OnIceCandidateError( const String& error_text) { DCHECK(task_runner_->RunsTasksInCurrentSequence()); TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::OnIceCandidateError"); - if (peer_connection_tracker_) { peer_connection_tracker_->TrackIceCandidateError( this, address, port, host_candidate, url, error_code, error_text); |