Addresses #2121 refs[t:2121] toku_ydb_lock_destroy(): After freeing thread-specific memory for ydbtime struct,

set thread-specific storage to NULL to prevent destructor (toku_free) from being called twice,
just in case the thread that calls toku_ydb_lock_destroy() is not the same thread that called 
toku_ydb_lock_init().


git-svn-id: file:///svn/toku/tokudb@15976 c7de825b-a66e-492c-adef-691d508d4ae1
This commit is contained in:
Barry Perlman 2013-04-16 23:58:54 -04:00 committed by Yoni Fogel
parent c2d7c68f56
commit 87bbf72c70

View file

@ -107,8 +107,15 @@ toku_ydb_lock_destroy(void) {
int r;
r = toku_pthread_mutex_destroy(&ydb_big_lock.lock); assert(r == 0);
#if YDB_LOCK_MISS_TIME
// If main thread calls here, free memory allocated to main thread
// because destructor would not be called on thread exit.
void * last_ydbtime = toku_pthread_getspecific(ydb_big_lock.time_key);
if (last_ydbtime) toku_free(last_ydbtime);
// If some other thread (not main thread) calls here
// set the value to NULL so destructor is not called twice
r = toku_pthread_setspecific(ydb_big_lock.time_key, NULL); assert(r==0);
r = toku_pthread_key_delete(ydb_big_lock.time_key); assert(r == 0);
#endif
return r;