@@ -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