Skip to content

Commit

Permalink
Bug 1551836: Ensure that we clean up PeerConnectionMedia properly whe…
Browse files Browse the repository at this point in the history
…n PeerConnectionImpl::Initialize fails. r=mjf

Differential Revision: https://phabricator.services.mozilla.com/D33071
  • Loading branch information
docfaraday committed Jun 4, 2019
1 parent c39d759 commit 498e7bc
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ PeerConnectionImpl::~PeerConnectionImpl() {
// probably want to shut it down more aggressively to save memory. We
// could shut down here when there are no uses. It might be more optimal
// to release off a timer (and XPCOM Shutdown) to avoid churn
ShutdownMedia();
}

nsresult PeerConnectionImpl::Initialize(PeerConnectionObserver& aObserver,
Expand Down Expand Up @@ -469,27 +470,6 @@ nsresult PeerConnectionImpl::Initialize(PeerConnectionObserver& aObserver,
return NS_ERROR_FAILURE;
}

mMedia = new PeerConnectionMedia(this);

// Connect ICE slots.
mMedia->SignalIceGatheringStateChange.connect(
this, &PeerConnectionImpl::IceGatheringStateChange);
mMedia->SignalUpdateDefaultCandidate.connect(
this, &PeerConnectionImpl::UpdateDefaultCandidate);
mMedia->SignalIceConnectionStateChange.connect(
this, &PeerConnectionImpl::IceConnectionStateChange);

mMedia->SignalCandidate.connect(this, &PeerConnectionImpl::CandidateReady);

// Initialize the media object.
res = mMedia->Init();
if (NS_FAILED(res)) {
CSFLogError(LOGTAG, "%s: Couldn't initialize media object", __FUNCTION__);
return res;
}

PeerConnectionCtx::GetInstance()->mPeerConnections[mHandle] = this;

mJsepSession =
MakeUnique<JsepSessionImpl>(mName, MakeUnique<PCUuidGenerator>());

Expand Down Expand Up @@ -523,6 +503,27 @@ nsresult PeerConnectionImpl::Initialize(PeerConnectionObserver& aObserver,
return res;
}

mMedia = new PeerConnectionMedia(this);

// Initialize the media object.
res = mMedia->Init();
if (NS_FAILED(res)) {
CSFLogError(LOGTAG, "%s: Couldn't initialize media object", __FUNCTION__);
ShutdownMedia();
return res;
}

// Connect ICE slots.
mMedia->SignalIceGatheringStateChange.connect(
this, &PeerConnectionImpl::IceGatheringStateChange);
mMedia->SignalUpdateDefaultCandidate.connect(
this, &PeerConnectionImpl::UpdateDefaultCandidate);
mMedia->SignalIceConnectionStateChange.connect(
this, &PeerConnectionImpl::IceConnectionStateChange);
mMedia->SignalCandidate.connect(this, &PeerConnectionImpl::CandidateReady);

PeerConnectionCtx::GetInstance()->mPeerConnections[mHandle] = this;

return NS_OK;
}

Expand Down

0 comments on commit 498e7bc

Please sign in to comment.