o Initialize a local variable before referencing it. This was not

the cause of any bugs because it is *always* indirectly set
  in the for...loop, but better to be explicit about it.
o Check the magic number of the passed in thread only after it has
  been found in the active thread list. Otherwise, if the check is done
  at the very beginning we may end up pointing to garbage if the
  thread was once a valid thread, but has now been destroyed.
This commit is contained in:
Mike Makonnen 2004-03-26 14:45:35 +00:00
parent ab82970ed2
commit 8733f60328

View File

@ -41,18 +41,21 @@ _find_thread(pthread_t pthread)
{
pthread_t pthread1;
if (pthread == NULL || pthread->magic != PTHREAD_MAGIC)
if (pthread == NULL)
return(EINVAL);
THREAD_LIST_LOCK;
/* Search for the specified thread: */
pthread1 = NULL;
TAILQ_FOREACH(pthread1, &_thread_list, tle) {
if (pthread == pthread1)
break;
}
THREAD_LIST_UNLOCK;
if (pthread1 != NULL && pthread1->magic != PTHREAD_MAGIC)
return (EINVAL);
/* Return zero if the thread exists: */
return ((pthread1 != NULL) ? 0:ESRCH);