Skip to content

Commit

Permalink
Bug 1374038 - _exit() can call static destructors on Windows! So repl…
Browse files Browse the repository at this point in the history
…ace it with TerminateProcess which can't, r=jimm r=mstange

MozReview-Commit-ID: FSsOU85yA18

--HG--
extra : rebase_source : 7247a9940d7729e003af51c0cc7de15b08aa54d0
  • Loading branch information
bsmedberg committed Jul 17, 2017
1 parent 137d61d commit e92ddc2
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions widget/windows/nsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5052,6 +5052,24 @@ nsWindow::ExternalHandlerProcessMessage(UINT aMessage,
return false;
}

/**
* the _exit() call is not a safe way to terminate your own process on
* Windows, because _exit runs DLL detach callbacks which run static
* destructors for xul.dll.
*
* This method terminates the current process without those issues.
*/
static void
ExitThisProcessSafely()
{
HANDLE process = GetCurrentProcess();
if (TerminateProcess(GetCurrentProcess(), 0)) {
// TerminateProcess is asynchronous, so we wait on our own process handle
WaitForSingleObject(process, INFINITE);
}
MOZ_CRASH("Just in case extremis crash in ExitThisProcessSafely.");
}

// The main windows message processing method.
bool
nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam,
Expand Down Expand Up @@ -5136,8 +5154,7 @@ nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam,
obsServ->NotifyObservers(nullptr, "profile-before-change", context);
obsServ->NotifyObservers(nullptr, "profile-before-change-qm", context);
obsServ->NotifyObservers(nullptr, "profile-before-change-telemetry", context);
// Then a controlled but very quick exit.
_exit(0);
ExitThisProcessSafely();
}
sCanQuit = TRI_UNKNOWN;
result = true;
Expand Down

0 comments on commit e92ddc2

Please sign in to comment.