Bug 1542593 - Don't access gNeckoChild if not on main thread r=jdm
authorKershaw Chang <kershaw@mozilla.com>
Thu, 02 May 2019 17:29:46 +0000
changeset 531278 6c982370080bbaed64a58475ec21db59dfe8327a
parent 531277 a43b68bbe67db228211e414a6e33490ce46a8ba4
child 531279 fa5584298300bbff34cdaa3001ac248e4b4003a7
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
bugs1542593
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1542593 - Don't access gNeckoChild if not on main thread r=jdm gNeckoChild is only accessed on main thread, so we should use NS_IsMainThread to see whether we should access gNeckoChild or not. This patch also makes UDPSocketChild::Bind return NS_ERROR_NOT_AVAILABLE when mBackgroundManager is null. Differential Revision: https://phabricator.services.mozilla.com/D29658
dom/network/UDPSocketChild.cpp
--- a/dom/network/UDPSocketChild.cpp
+++ b/dom/network/UDPSocketChild.cpp
@@ -72,32 +72,41 @@ UDPSocketChild::Bind(nsIUDPSocketInterna
                      bool aAddressReuse, bool aLoopback,
                      uint32_t recvBufferSize, uint32_t sendBufferSize,
                      nsIEventTarget* aMainThreadEventTarget) {
   UDPSOCKET_LOG(
       ("%s: %s:%u", __FUNCTION__, PromiseFlatCString(aHost).get(), aPort));
 
   NS_ENSURE_ARG(aSocket);
 
-  mSocket = aSocket;
-  AddIPDLReference();
+  if (NS_IsMainThread()) {
+    if (aMainThreadEventTarget) {
+      gNeckoChild->SetEventTargetForActor(this, aMainThreadEventTarget);
+    }
+    if (!gNeckoChild->SendPUDPSocketConstructor(
+            this, IPC::Principal(aPrincipal), mFilterName)) {
+      return NS_ERROR_FAILURE;
+    }
+  } else {
+    if (!mBackgroundManager) {
+      return NS_ERROR_NOT_AVAILABLE;
+    }
 
-  if (mBackgroundManager) {
     // If we want to support a passed-in principal here we'd need to
     // convert it to a PrincipalInfo
     MOZ_ASSERT(!aPrincipal);
-    mBackgroundManager->SendPUDPSocketConstructor(this, Nothing(), mFilterName);
-  } else {
-    if (aMainThreadEventTarget) {
-      gNeckoChild->SetEventTargetForActor(this, aMainThreadEventTarget);
+    if (!mBackgroundManager->SendPUDPSocketConstructor(this, Nothing(),
+                                                       mFilterName)) {
+      return NS_ERROR_FAILURE;
     }
-    gNeckoChild->SendPUDPSocketConstructor(this, IPC::Principal(aPrincipal),
-                                           mFilterName);
   }
 
+  mSocket = aSocket;
+  AddIPDLReference();
+
   SendBind(UDPAddressInfo(nsCString(aHost), aPort), aAddressReuse, aLoopback,
            recvBufferSize, sendBufferSize);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 UDPSocketChild::Connect(nsIUDPSocketInternal* aSocket, const nsACString& aHost,
                         uint16_t aPort) {