gohome1984 / google-breakpad

Automatically exported from code.google.com/p/google-breakpad
0 stars 0 forks source link

TerminateThread in ~ExceptionHandler may cause process exit code to change on Windows. #280

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
On Windows, when using breakpad in a tool whose exit code is important, the 
TerminateThread call 
in the ExceptionHandler destructor may cause the process exit code to become 1 
even if main() 
returned 0.
This may happen when the exception handler thread terminates after the main 
thread. On Windows, 
the process exit code is the exit code of the last thread terminated, so even 
if main() returned 0 as 
the exit code, the process exit code may turn to 1 if the exception handler 
thread terminates after 
the main thread.

(In most cases, this may not be visible, because (a) the thread terminates 
early enough and (b) the 
exit code is not important, i.e. it's not checked by the parent process).

One obvious fix is to call WaitForSingleObject to wait for the exception 
handler thread termination 
in ExceptionHandler::~ ExceptionHandler() after having called TerminateThread.

Original issue reported on code.google.com by j...@mac.com on 24 Nov 2008 at 12:13

GoogleCodeExporter commented 9 years ago
I wish I had noticed this earlier! We hit this in Firefox:
https://bugzilla.mozilla.org/show_bug.cgi?id=535585

As a workaround, you can currently compile with -DBREAKPAD_NO_TERMINATE_THREAD.

Original comment by ted.mielczarek on 31 Jan 2010 at 11:25