Bug 1402836 - Avoid racing while destroying JS shell contexts, r=jandem.
authorBrian Hackett <bhackett1024@gmail.com>
Thu, 12 Oct 2017 05:23:29 -0700
changeset 386025 8adc032add4e21b85ff4eaa31ae0074434dc2a12
parent 386024 d6fdc1d3b07044a6cd84adcc433d3f6a943dca20
child 386026 750de14d83712561cc6b274518b1f7096c83b7cc
push id32673
push userarchaeopteryx@coole-files.de
push dateFri, 13 Oct 2017 09:13:17 +0000
treeherdermozilla-central@196dadb2fe50 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1402836
milestone58.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 1402836 - Avoid racing while destroying JS shell contexts, r=jandem.
js/src/shell/js.cpp
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -3538,33 +3538,33 @@ WorkerMain(void* arg)
     JSContext* cx = input->parentRuntime
          ? JS_NewContext(8L * 1024L * 1024L, 2L * 1024L * 1024L, input->parentRuntime)
          : JS_NewCooperativeContext(input->siblingContext);
     if (!cx)
         return;
 
     SetCooperativeYieldCallback(cx, CooperativeYieldCallback);
 
-    UniquePtr<ShellContext> sc = MakeUnique<ShellContext>(cx);
+    ShellContext* sc = js_new<ShellContext>(cx);
     if (!sc)
         return;
 
     auto guard = mozilla::MakeScopeExit([&] {
-        if (cx)
-            JS_DestroyContext(cx);
+        JS_DestroyContext(cx);
+        js_delete(sc);
         if (input->siblingContext) {
             cooperationState->numThreads--;
             CooperativeYield();
         }
         js_delete(input);
     });
 
     if (input->parentRuntime)
         sc->isWorker = true;
-    JS_SetContextPrivate(cx, sc.get());
+    JS_SetContextPrivate(cx, sc);
     SetWorkerContextOptions(cx);
     JS::SetBuildIdOp(cx, ShellBuildId);
 
     Maybe<EnvironmentPreparer> environmentPreparer;
     if (input->parentRuntime) {
         JS_SetFutexCanWait(cx);
         JS::SetWarningReporter(cx, WarningReporter);
         js::SetPreserveWrapperCallback(cx, DummyPreserveWrapperCallback);
@@ -3576,17 +3576,17 @@ WorkerMain(void* arg)
             return;
 
         environmentPreparer.emplace(cx);
     } else {
         JS_AddInterruptCallback(cx, ShellInterruptCallback);
 
         // The Gecko Profiler requires that all cooperating contexts have
         // profiling stacks installed.
-        MOZ_ALWAYS_TRUE(EnsureGeckoProfilingStackInstalled(cx, sc.get()));
+        MOZ_ALWAYS_TRUE(EnsureGeckoProfilingStackInstalled(cx, sc));
     }
 
     do {
         JSAutoRequest ar(cx);
 
         JS::CompartmentOptions compartmentOptions;
         SetStandardCompartmentOptions(compartmentOptions);
         if (input->siblingContext)