diff options
author | mark@chromium.org <mark@chromium.org@4c0a9323-5329-0410-9bdc-e9ce6186880e> | 2014-01-10 19:54:20 +0000 |
---|---|---|
committer | mark@chromium.org <mark@chromium.org@4c0a9323-5329-0410-9bdc-e9ce6186880e> | 2014-01-10 19:54:20 +0000 |
commit | 3ea04ec4794537a1e392f5cad4e352f4c9722553 (patch) | |
tree | cd342c3a630773e5ecb15a240fe30e79fcd23fab /src/client | |
parent | Fix #include order from r1268. (diff) | |
download | breakpad-3ea04ec4794537a1e392f5cad4e352f4c9722553.tar.xz |
Don't do work inside assert(). Ever.
The Mac crash key manipulation code was intended to be thread-safe through the
provision of a mutex. The mutex operations were done inside an assert().
assert() is a no-op in NDEBUG (release) builds. Therefore, in release builds,
these operations were occurring without being protected by any mutex at all,
and were nowhere near thread-safe.
BUG=chromium:331268
R=rsesek@chromium.org
Review URL: https://breakpad.appspot.com/1034002
git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@1270 4c0a9323-5329-0410-9bdc-e9ce6186880e
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/ios/Breakpad.mm | 29 | ||||
-rw-r--r-- | src/client/mac/Framework/Breakpad.mm | 29 |
2 files changed, 26 insertions, 32 deletions
diff --git a/src/client/ios/Breakpad.mm b/src/client/ios/Breakpad.mm index c46509e8..3b9f6d3f 100644 --- a/src/client/ios/Breakpad.mm +++ b/src/client/ios/Breakpad.mm @@ -31,6 +31,7 @@ #import "client/ios/Breakpad.h" +#include <assert.h> #import <Foundation/Foundation.h> #include <pthread.h> #include <sys/stat.h> @@ -91,36 +92,32 @@ pthread_mutex_t gDictionaryMutex; // ProtectedMemoryLocker will unprotect this block after taking the lock. // Its destructor will first re-protect the memory then release the lock. class ProtectedMemoryLocker { -public: - // allocator may be NULL, in which case no Protect() or Unprotect() calls - // will be made, but a lock will still be taken + public: ProtectedMemoryLocker(pthread_mutex_t *mutex, ProtectedMemoryAllocator *allocator) - : mutex_(mutex), allocator_(allocator) { + : mutex_(mutex), + allocator_(allocator) { // Lock the mutex - assert(pthread_mutex_lock(mutex_) == 0); + int rv = pthread_mutex_lock(mutex_); + assert(rv == 0); // Unprotect the memory - if (allocator_ ) { - allocator_->Unprotect(); - } + allocator_->Unprotect(); } ~ProtectedMemoryLocker() { // First protect the memory - if (allocator_) { - allocator_->Protect(); - } + allocator_->Protect(); // Then unlock the mutex - assert(pthread_mutex_unlock(mutex_) == 0); + int rv = pthread_mutex_unlock(mutex_); + assert(rv == 0); }; -private: - // Keep anybody from ever creating one of these things not on the stack. - ProtectedMemoryLocker() { } + private: + ProtectedMemoryLocker(); ProtectedMemoryLocker(const ProtectedMemoryLocker&); - ProtectedMemoryLocker & operator=(ProtectedMemoryLocker&); + ProtectedMemoryLocker& operator=(const ProtectedMemoryLocker&); pthread_mutex_t *mutex_; ProtectedMemoryAllocator *allocator_; diff --git a/src/client/mac/Framework/Breakpad.mm b/src/client/mac/Framework/Breakpad.mm index a1336475..0b3fa715 100644 --- a/src/client/mac/Framework/Breakpad.mm +++ b/src/client/mac/Framework/Breakpad.mm @@ -33,6 +33,7 @@ #import "client/mac/Framework/Breakpad.h" +#include <assert.h> #import <Foundation/Foundation.h> #include <pthread.h> #include <sys/stat.h> @@ -95,36 +96,32 @@ pthread_mutex_t gDictionaryMutex; // ProtectedMemoryLocker will unprotect this block after taking the lock. // Its destructor will first re-protect the memory then release the lock. class ProtectedMemoryLocker { -public: - // allocator may be NULL, in which case no Protect() or Unprotect() calls - // will be made, but a lock will still be taken + public: ProtectedMemoryLocker(pthread_mutex_t *mutex, ProtectedMemoryAllocator *allocator) - : mutex_(mutex), allocator_(allocator) { + : mutex_(mutex), + allocator_(allocator) { // Lock the mutex - assert(pthread_mutex_lock(mutex_) == 0); + int rv = pthread_mutex_lock(mutex_); + assert(rv == 0); // Unprotect the memory - if (allocator_ ) { - allocator_->Unprotect(); - } + allocator_->Unprotect(); } ~ProtectedMemoryLocker() { // First protect the memory - if (allocator_) { - allocator_->Protect(); - } + allocator_->Protect(); // Then unlock the mutex - assert(pthread_mutex_unlock(mutex_) == 0); + int rv = pthread_mutex_unlock(mutex_); + assert(rv == 0); }; -private: - // Keep anybody from ever creating one of these things not on the stack. - ProtectedMemoryLocker() { } + private: + ProtectedMemoryLocker(); ProtectedMemoryLocker(const ProtectedMemoryLocker&); - ProtectedMemoryLocker & operator=(ProtectedMemoryLocker&); + ProtectedMemoryLocker& operator=(const ProtectedMemoryLocker&); pthread_mutex_t *mutex_; ProtectedMemoryAllocator *allocator_; |