Bug 1411977 - Part 5: Don't pass a pointer to a temporary to NotifyDataChannel_m. r?drno
MozReview-Commit-ID: 3ydeM9U1P4b
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
@@ -1413,41 +1413,35 @@ static void NotifyDataChannel_m(RefPtr<n
NS_DataChannelAppReady(aChannel);
}
void
PeerConnectionImpl::NotifyDataChannel(already_AddRefed<DataChannel> aChannel)
{
PC_AUTO_ENTER_API_CALL_NO_CHECK();
- // XXXkhuey this is completely fucked up. We can't use RefPtr<DataChannel>
- // here because DataChannel's AddRef/Release are non-virtual and not visible
- // if !MOZILLA_INTERNAL_API, but this function leaks the DataChannel if
- // !MOZILLA_INTERNAL_API because it never transfers the ref to
- // NS_NewDOMDataChannel.
- DataChannel* channel = aChannel.take();
+ RefPtr<DataChannel> channel(aChannel);
MOZ_ASSERT(channel);
-
- CSFLogDebug(LOGTAG, "%s: channel: %p", __FUNCTION__, channel);
+ CSFLogDebug(LOGTAG, "%s: channel: %p", __FUNCTION__, channel.get());
nsCOMPtr<nsIDOMDataChannel> domchannel;
- nsresult rv = NS_NewDOMDataChannel(already_AddRefed<DataChannel>(channel),
+ nsresult rv = NS_NewDOMDataChannel(channel.forget(),
mWindow, getter_AddRefs(domchannel));
NS_ENSURE_SUCCESS_VOID(rv);
mHaveDataStream = true;
RefPtr<PeerConnectionObserver> pco = do_QueryObjectReferent(mPCObserver);
if (!pco) {
return;
}
RUN_ON_THREAD(mThread,
WrapRunnableNM(NotifyDataChannel_m,
- domchannel.get(),
+ domchannel.forget(),
pco),
NS_DISPATCH_NORMAL);
}
NS_IMETHODIMP
PeerConnectionImpl::CreateOffer(const RTCOfferOptions& aOptions)
{
JsepOfferOptions options;