Bug 708629. Avoid using uninitialized pkey_stack. r=bgirard

This was causing crashes with make check/xpcshell on OS X.
This commit is contained in:
Jeff Muizelaar 2011-12-08 10:46:02 -05:00
parent 8276992ccf
commit 1183428944
2 changed files with 16 additions and 0 deletions

View File

@ -52,6 +52,11 @@ using std::string;
pthread_key_t pkey_stack;
pthread_key_t pkey_ticker;
// We need to track whether we've been initialized otherwise
// we end up using pkey_stack without initializing it.
// Because pkey_stack is totally opaque to us we can't reuse
// it as the flag itself.
bool stack_key_initialized;
TimeStamp sLastTracerEvent;
@ -378,6 +383,7 @@ void mozilla_sampler_init()
LOG("Failed to init.");
return;
}
stack_key_initialized = true;
Stack *stack = new Stack();
pthread_setspecific(pkey_stack, stack);

View File

@ -47,6 +47,7 @@ using mozilla::TimeDuration;
// TODO Merge into Sampler.h
extern pthread_key_t pkey_stack;
extern bool stack_key_initialized;
#define SAMPLER_INIT() mozilla_sampler_init();
#define SAMPLER_DEINIT() mozilla_sampler_deinit();
@ -194,7 +195,16 @@ public:
inline void* mozilla_sampler_call_enter(const char *aInfo)
{
// check if we've been initialized to avoid calling pthread_getspecific
// with a null pkey_stack which will return undefined results.
if (!stack_key_initialized)
return NULL;
Stack *stack = (Stack*)pthread_getspecific(pkey_stack);
// we can't infer whether 'stack' has been initialized
// based on the value of stack_key_intiailized because
// 'stack' is only intialized when a thread is being
// profiled.
if (!stack) {
return stack;
}