Index: src/OFThread.h ================================================================== --- src/OFThread.h +++ src/OFThread.h @@ -53,10 +53,11 @@ */ @interface OFThread: OFObject { id object; of_thread_t thread; + BOOL running; @public id retval; } Index: src/OFThread.m ================================================================== --- src/OFThread.m +++ src/OFThread.m @@ -65,13 +65,16 @@ self = [super init]; object = [obj copy]; if (!of_thread_new(&thread, call_main, self)) { Class c = isa; + [object release]; [super dealloc]; @throw [OFInitializationFailedException newWithClass: c]; } + + running = YES; return self; } - main @@ -80,10 +83,11 @@ } - join { of_thread_join(thread); + running = NO; return retval; } - (void)dealloc @@ -91,11 +95,12 @@ /* * No need to handle errors - if canceling the thread fails, we can't * do anything anyway. Most likely, it finished already or was already * canceled. */ - of_thread_cancel(thread); + if (running) + of_thread_cancel(thread); [object release]; [super dealloc]; } @end