diff --git a/blink/renderer/modules/peerconnection/rtc_peer_connection_handler.cc b/blink/renderer/modules/peerconnection/rtc_peer_connection_handler.cc index e76746e9ce4d93759709adeda4cff7447c7e0313..9634a17050ab5b9e35afbc925e1bd258714008ed 100644 --- a/blink/renderer/modules/peerconnection/rtc_peer_connection_handler.cc +++ b/blink/renderer/modules/peerconnection/rtc_peer_connection_handler.cc @@ -1059,15 +1059,19 @@ bool RTCPeerConnectionHandler::Initialize( WebLocalFrame* frame, ExceptionState& exception_state) { DCHECK(task_runner_->RunsTasksInCurrentSequence()); - DCHECK(frame); DCHECK(dependency_factory_); - frame_ = frame; CHECK(!initialize_called_); initialize_called_ = true; // Prevent garbage collection of client_ during processing. auto* client_on_stack = client_; + if (!client_on_stack) { + return false; + } + + DCHECK(frame); + frame_ = frame; peer_connection_tracker_ = PeerConnectionTracker::From(*frame); configuration_ = server_configuration; @@ -2267,10 +2271,13 @@ void RTCPeerConnectionHandler::OnIceCandidate(const String& sdp, int sdp_mline_index, int component, int address_family) { + DCHECK(task_runner_->RunsTasksInCurrentSequence()); // 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()); + if (!client_on_stack) { + return; + } TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::OnIceCandidateImpl"); // This line can cause garbage collection. auto* platform_candidate = MakeGarbageCollected(