Bug 1117977, make script load handling during shutdown safer, r=mccr8
☠☠ backed out by 2b2f1d308c3a ☠ ☠
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Thu, 19 Feb 2015 01:18:27 +0200
changeset 256853 d77323edbdec08e3b234b8385cb23b70063ff02f
parent 256852 d880fdc6fb00371b5cdcac60b383d62081aa5e18
child 256854 1703a6a1028fc1f587e5a7312835dad4a2f1a6ca
push id4610
push userjlund@mozilla.com
push dateMon, 30 Mar 2015 18:32:55 +0000
treeherdermozilla-beta@4df54044d9ef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1117977
milestone38.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 1117977, make script load handling during shutdown safer, r=mccr8
dom/base/nsScriptLoader.cpp
--- a/dom/base/nsScriptLoader.cpp
+++ b/dom/base/nsScriptLoader.cpp
@@ -791,16 +791,18 @@ class NotifyOffThreadScriptLoadCompleted
   void *mToken;
 
 public:
   NotifyOffThreadScriptLoadCompletedRunnable(nsScriptLoadRequest* aRequest,
                                              nsScriptLoader* aLoader)
     : mRequest(aRequest), mLoader(aLoader), mToken(nullptr)
   {}
 
+  virtual ~NotifyOffThreadScriptLoadCompletedRunnable();
+
   void SetToken(void* aToken) {
     MOZ_ASSERT(aToken && !mToken);
     mToken = aToken;
   }
 
   NS_DECL_NSIRUNNABLE
 };
 
@@ -809,16 +811,33 @@ public:
 nsresult
 nsScriptLoader::ProcessOffThreadRequest(nsScriptLoadRequest* aRequest, void **aOffThreadToken)
 {
   nsresult rv = ProcessRequest(aRequest, aOffThreadToken);
   mDocument->UnblockOnload(false);
   return rv;
 }
 
+NotifyOffThreadScriptLoadCompletedRunnable::~NotifyOffThreadScriptLoadCompletedRunnable()
+{
+  if (MOZ_UNLIKELY(mRequest || mLoader) && !NS_IsMainThread()) {
+    nsCOMPtr<nsIThread> mainThread;
+    NS_GetMainThread(getter_AddRefs(mainThread));
+    if (mainThread) {
+      NS_ProxyRelease(mainThread, mRequest);
+      NS_ProxyRelease(mainThread, mLoader);
+    } else {
+      MOZ_ASSERT(false, "We really shouldn't leak!");
+      // Better to leak than crash.
+      unused << mRequest.forget();
+      unused << mLoader.forget();
+    }
+  }
+}
+
 NS_IMETHODIMP
 NotifyOffThreadScriptLoadCompletedRunnable::Run()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   // We want these to be dropped on the main thread, once we return from this
   // function.
   nsRefPtr<nsScriptLoadRequest> request = mRequest.forget();