Index: src/OFThread.h ================================================================== --- src/OFThread.h +++ src/OFThread.h @@ -22,10 +22,11 @@ @public of_tlskey_t key; @protected void (*destructor)(id); of_list_object_t *listobj; + BOOL initialized; } /** * \return A new autoreleased Thread Local Storage key */ @@ -167,10 +168,11 @@ * \brief A class for creating mutual exclusions. */ @interface OFMutex: OFObject { of_mutex_t mutex; + BOOL initialized; } /** * \return A new autoreleased mutex. */ Index: src/OFThread.m ================================================================== --- src/OFThread.m +++ src/OFThread.m @@ -239,11 +239,11 @@ @try { if (!of_tlskey_new(&key)) @throw [OFInitializationFailedException newWithClass: isa]; - destructor = NULL; + initialized = YES; @synchronized (tlskeys) { listobj = [tlskeys appendObject: self]; } } @catch (id e) { @@ -266,11 +266,12 @@ - (void)dealloc { if (destructor != NULL) destructor(self); - of_tlskey_free(key); + if (initialized) + of_tlskey_free(key); /* In case we called [self release] in init */ if (listobj != NULL) { @synchronized (tlskeys) { [tlskeys removeListObject: listobj]; @@ -295,10 +296,12 @@ Class c = isa; [self release]; @throw [OFInitializationFailedException newWithClass: c]; } + initialized = YES; + return self; } - (void)lock { @@ -317,10 +320,11 @@ @throw [OFMutexUnlockFailedException newWithClass: isa]; } - (void)dealloc { - of_mutex_free(&mutex); + if (initialized) + of_mutex_free(&mutex); [super dealloc]; } @end