Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Unified Diff: client/windows/handler/exception_handler.cc

Issue 13065: Protect the exception handler against failure to create semaphores & a thread... (Closed) Base URL: http://google-breakpad.googlecode.com/svn/trunk/src/
Patch Set: Created 12 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/windows/handler/exception_handler.cc
===================================================================
--- client/windows/handler/exception_handler.cc (revision 285)
+++ client/windows/handler/exception_handler.cc (working copy)
@@ -140,15 +140,22 @@
// context outside of an exception.
InitializeCriticalSection(&handler_critical_section_);
handler_start_semaphore_ = CreateSemaphore(NULL, 0, 1, NULL);
+ assert(handler_start_semaphore_ != NULL);
+
handler_finish_semaphore_ = CreateSemaphore(NULL, 0, 1, NULL);
+ assert(handler_finish_semaphore_ != NULL);
- DWORD thread_id;
- handler_thread_ = CreateThread(NULL, // lpThreadAttributes
- kExceptionHandlerThreadInitialStackSize,
- ExceptionHandlerThreadMain,
- this, // lpParameter
- 0, // dwCreationFlags
- &thread_id);
+ // Don't attempt to create the thread if we could not create the semaphores.
+ if (handler_finish_semaphore_ != NULL && handler_start_semaphore_ != NULL) {
+ DWORD thread_id;
+ handler_thread_ = CreateThread(NULL, // lpThreadAttributes
+ kExceptionHandlerThreadInitialStackSize,
+ ExceptionHandlerThreadMain,
+ this, // lpParameter
+ 0, // dwCreationFlags
+ &thread_id);
+ assert(handler_thread_ != NULL);
+ }
dbghelp_module_ = LoadLibrary(L"dbghelp.dll");
if (dbghelp_module_) {
@@ -264,6 +271,8 @@
DWORD ExceptionHandler::ExceptionHandlerThreadMain(void* lpParameter) {
ExceptionHandler* self = reinterpret_cast<ExceptionHandler *>(lpParameter);
assert(self);
+ assert(self->handler_start_semaphore_ != NULL);
+ assert(self->handler_finish_semaphore_ != NULL);
while (true) {
if (WaitForSingleObject(self->handler_start_semaphore_, INFINITE) ==
@@ -519,6 +528,17 @@
EXCEPTION_POINTERS* exinfo, MDRawAssertionInfo* assertion) {
EnterCriticalSection(&handler_critical_section_);
+ // There isn't much we can do if the handler thread
+ // was not successfully created.
+ if (handler_thread_ == NULL) {
+ LeaveCriticalSection(&handler_critical_section_);
+ return false;
+ }
+
+ // The handler thread should only be created when the semaphores are valid.
+ assert(handler_start_semaphore_ != NULL);
+ assert(handler_finish_semaphore_ != NULL);
+
// Set up data to be passed in to the handler thread.
requesting_thread_id_ = GetCurrentThreadId();
exception_info_ = exinfo;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698