From b24b33e2bbb552d44b0a5cb55574f1f55d33ad12 Mon Sep 17 00:00:00 2001 From: rfm Date: Sat, 14 Feb 2015 05:50:48 +0000 Subject: [PATCH] fix for bug # 44240 git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@38340 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 7 +++++++ Source/NSThread.m | 41 +++++++++++++++++++++++------------------ 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 569dba8a3..fe0e94109 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2015-02-14 Richard Frith-Macdonald + + * Source/NSThread.m: Be more agressive about releasing thread + resources when a thread exists (in particular release the + thread's runloop repeatedly for bug #44240) in case of the + deallocation of objects causing re-population of thread data. + 2015-02-07 Richard Frith-Macdonald * Source/NSData.m: Simplify mingw/unixy ifdefs for writing a file. diff --git a/Source/NSThread.m b/Source/NSThread.m index 80d389b2c..9cd7577db 100644 --- a/Source/NSThread.m +++ b/Source/NSThread.m @@ -710,18 +710,14 @@ unregisterActiveThread(NSThread *thread) - (void) dealloc { + int retries = 0; + if (_active == YES) { [NSException raise: NSInternalInconsistencyException format: @"Deallocating an active thread without [+exit]!"]; } - if (_runLoopInfo != 0) - { - GSRunLoopThreadInfo *info = (GSRunLoopThreadInfo*)_runLoopInfo; - - _runLoopInfo = 0; - [info release]; - } + DESTROY(_runLoopInfo); DESTROY(_thread_dictionary); DESTROY(_target); DESTROY(_arg); @@ -731,24 +727,33 @@ unregisterActiveThread(NSThread *thread) [NSAutoreleasePool _endThread: self]; } - if (_thread_dictionary != nil) + while ((_thread_dictionary != nil || _runLoopInfo != nil) && retries++ < 10) { - /* - * Try again to get rid of thread dictionary. + /* Try again. */ + DESTROY(_runLoopInfo); DESTROY(_thread_dictionary); if (_autorelease_vars.pool_cache != 0) { [NSAutoreleasePool _endThread: self]; } - if (_thread_dictionary != nil) - { - NSLog(@"Oops - leak - thread dictionary is %@", _thread_dictionary); - if (_autorelease_vars.pool_cache != 0) - { - [NSAutoreleasePool _endThread: self]; - } - } + } + + if (_runLoopInfo != nil) + { + NSLog(@"Oops - leak - run loop is %@", _runLoopInfo); + if (_autorelease_vars.pool_cache != 0) + { + [NSAutoreleasePool _endThread: self]; + } + } + if (_thread_dictionary != nil) + { + NSLog(@"Oops - leak - thread dictionary is %@", _thread_dictionary); + if (_autorelease_vars.pool_cache != 0) + { + [NSAutoreleasePool _endThread: self]; + } } DESTROY(_gcontext); [super dealloc];