Bug 1411977 - Part 5: Don't pass a pointer to a temporary to NotifyDataChannel_m. r?drno draft
authorByron Campen [:bwc] <docfaraday@gmail.com>
Thu, 25 Jan 2018 10:04:55 -0600
changeset 748503 07bdde0c57c1effc5823aadbc68c39d90dd096ce
parent 748502 5e85c43884ed35648af92b08128ff6078099b083
child 748504 5001484185a5dd0662151c9d0c8c05709b1d6bda
push id97190
push userbcampen@mozilla.com
push dateMon, 29 Jan 2018 22:41:18 +0000
reviewersdrno
bugs1411977
milestone60.0a1
Bug 1411977 - Part 5: Don't pass a pointer to a temporary to NotifyDataChannel_m. r?drno MozReview-Commit-ID: 3ydeM9U1P4b
media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
--- 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;