From c5ca5644d35b1fbad9c367e78cc5d38566f584e4 Mon Sep 17 00:00:00 2001 From: vasiljevic Date: Fri, 2 Apr 2010 15:53:52 +0000 Subject: * generic/tclThreadStorage.c (ThreadStorageGetHashTable): avoid accessing shared table index w/o mutex protection. --- ChangeLog | 8 ++++++-- generic/tclThreadStorage.c | 19 +++++++------------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4db08b9..085f07e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,12 @@ 2010-04-02 Zoran Vasiljevic * generic/tclStringObj.c: (SetStringFromAny): avoid trampling - over the tclEmptyStringRep->bytes as it is thread-shared - (thx to Gustaf Neumann for the (hard) work of locating this one). + over the tclEmptyStringRep as it is thread-shared. + + * generic/tclThreadStorage.c (ThreadStorageGetHashTable): + avoid accessing shared table index w/o mutex protection. + + Thanks to Gustaf Neumann for the (hard) work. 2010-03-31 Donal K. Fellows diff --git a/generic/tclThreadStorage.c b/generic/tclThreadStorage.c index 55587b3..d24973f 100644 --- a/generic/tclThreadStorage.c +++ b/generic/tclThreadStorage.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclThreadStorage.c,v 1.15 2007/12/13 15:23:20 dgp Exp $ + * RCS: @(#) $Id: tclThreadStorage.c,v 1.15.2.1 2010/04/02 15:53:53 vasiljevic Exp $ */ #include "tclInt.h" @@ -172,8 +172,7 @@ FreeThreadStorageEntry( * ThreadStorageGetHashTable -- * * This procedure returns a hash table pointer to be used for thread - * storage for the specified thread. This assumes that thread storage - * lock is held. + * storage for the specified thread. * * Results: * A hash table pointer for the specified thread, or NULL if the hash @@ -193,17 +192,13 @@ ThreadStorageGetHashTable( int index = PTR2UINT(id) % STORAGE_CACHE_SLOTS; Tcl_HashEntry *hPtr; int isNew; + Tcl_HashTable *hashTablePtr; - /* - * It's important that we pick up the hash table pointer BEFORE comparing - * thread Id in case another thread is in the critical region changing - * things out from under you. - */ + Tcl_MutexLock(&threadStorageLock); - Tcl_HashTable *hashTablePtr = threadStorageCache[index].hashTablePtr; + hashTablePtr = threadStorageCache[index].hashTablePtr; if (threadStorageCache[index].id != id) { - Tcl_MutexLock(&threadStorageLock); /* * It's not in the cache, so we look it up... @@ -257,10 +252,10 @@ ThreadStorageGetHashTable( threadStorageCache[index].id = id; threadStorageCache[index].hashTablePtr = hashTablePtr; - - Tcl_MutexUnlock(&threadStorageLock); } + Tcl_MutexUnlock(&threadStorageLock); + return hashTablePtr; } -- cgit v0.12