diff --git a/ChangeLog b/ChangeLog index e0d7ed872..8b4fcecfc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,17 @@ +2016-02-10 Richard Frith-Macdonald + + * Source/NSThread.m: In GSCurrentThread() the check for exiting + thread needs to NOT be wrapped in an exception handler, since the + exception handling code can attempt to get the current thread, + causing recursion. + 2016-02-09 Richard Frith-Macdonald * Source/NSUserDefaults.m: Remove dependency on NSUserDefaults in order to parse property list in program arguments ... get boolean defaults settings from the argument domain + 2016-02-09 Larry Campbell * Source/NSUserDefaults.m: Fix for bug #46956 diff --git a/Source/NSThread.m b/Source/NSThread.m index 6382c3abf..f8c0e5969 100644 --- a/Source/NSThread.m +++ b/Source/NSThread.m @@ -610,21 +610,17 @@ inline NSThread* GSCurrentThread(void) { NSThread *thr = pthread_getspecific(thread_object_key); + if (nil == thr) { NSValue *selfThread = NSValueCreateFromPthread(pthread_self()); + + /* NB this locked section cannot be protected by an exception handler + * because the exception handler stores information in the current + * thread variables ... which causes recursion. + */ [_exitingThreadsLock lock]; - NS_DURING - { - thr = NSMapGet(_exitingThreads, (const void*)selfThread); - } - NS_HANDLER - { - [_exitingThreadsLock unlock]; - DESTROY(selfThread); - [localException raise]; - } - NS_ENDHANDLER + thr = NSMapGet(_exitingThreads, (const void*)selfThread); [_exitingThreadsLock unlock]; DESTROY(selfThread); }