mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
Catch autoreleased objects during thread exit.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@22333 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
11f6c7fe38
commit
178aecf1db
4 changed files with 29 additions and 5 deletions
|
@ -1,3 +1,12 @@
|
|||
2006-01-19 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Headers/Foundation/NSThread.h:
|
||||
* Source/NSAutoreleasePool.m:
|
||||
* Source/NSThread.m:
|
||||
Mimic MacOS-X behavior and create an autorelease pool if necessary
|
||||
to catch any autorelease objects during thread exit.
|
||||
As suggested by Wim Oudshoorn..
|
||||
|
||||
2006-01-18 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/Additions/Unicode.m: fix for rare case where we could corrupt
|
||||
|
|
|
@ -35,8 +35,8 @@
|
|||
id _target;
|
||||
id _arg;
|
||||
SEL _selector;
|
||||
BOOL _active;
|
||||
@public
|
||||
BOOL _active;
|
||||
NSHandler *_exception_handler;
|
||||
NSMutableDictionary *_thread_dictionary;
|
||||
struct autorelease_thread_vars _autorelease_vars;
|
||||
|
|
|
@ -228,8 +228,14 @@ static IMP initImp;
|
|||
|
||||
+ (void) addObject: (id)anObj
|
||||
{
|
||||
NSAutoreleasePool *pool = ARP_THREAD_VARS->current_pool;
|
||||
NSThread *t = GSCurrentThread();
|
||||
NSAutoreleasePool *pool;
|
||||
|
||||
if (t->_active == NO)
|
||||
{
|
||||
[self new]; // Don't leak while exiting thread.
|
||||
}
|
||||
pool = t->_autorelease_vars.current_pool;
|
||||
if (pool != nil)
|
||||
{
|
||||
(*pool->_addImp)(pool, @selector(addObject:), anObj);
|
||||
|
|
|
@ -703,7 +703,10 @@ gnustep_base_thread_callback(void)
|
|||
DESTROY(_thread_dictionary);
|
||||
DESTROY(_target);
|
||||
DESTROY(_arg);
|
||||
[NSAutoreleasePool _endThread: self];
|
||||
if (_autorelease_vars.pool_cache != 0)
|
||||
{
|
||||
[NSAutoreleasePool _endThread: self];
|
||||
}
|
||||
|
||||
if (_thread_dictionary != nil)
|
||||
{
|
||||
|
@ -711,11 +714,17 @@ gnustep_base_thread_callback(void)
|
|||
* Try again to get rid of thread dictionary.
|
||||
*/
|
||||
DESTROY(_thread_dictionary);
|
||||
[NSAutoreleasePool _endThread: self];
|
||||
if (_autorelease_vars.pool_cache != 0)
|
||||
{
|
||||
[NSAutoreleasePool _endThread: self];
|
||||
}
|
||||
if (_thread_dictionary != nil)
|
||||
{
|
||||
NSLog(@"Oops - leak - thread dictionary is %@", _thread_dictionary);
|
||||
[NSAutoreleasePool _endThread: self];
|
||||
if (_autorelease_vars.pool_cache != 0)
|
||||
{
|
||||
[NSAutoreleasePool _endThread: self];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (self == defaultThread)
|
||||
|
|
Loading…
Reference in a new issue