diff options
author | mtm <mtm@FreeBSD.org> | 2004-03-26 14:45:35 +0000 |
---|---|---|
committer | mtm <mtm@FreeBSD.org> | 2004-03-26 14:45:35 +0000 |
commit | 8d2a2db80c442626cd971887c51d0c4cee277f38 (patch) | |
tree | 14b1e8ac9e7d77bffee09b374617233fb8226972 /lib | |
parent | a05bd8e51a2dd4d99901add51fa4d62117d2bcc7 (diff) | |
download | FreeBSD-src-8d2a2db80c442626cd971887c51d0c4cee277f38.zip FreeBSD-src-8d2a2db80c442626cd971887c51d0c4cee277f38.tar.gz |
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.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libthr/thread/thr_find_thread.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/libthr/thread/thr_find_thread.c b/lib/libthr/thread/thr_find_thread.c index bd51b8f..a00d19e 100644 --- a/lib/libthr/thread/thr_find_thread.c +++ b/lib/libthr/thread/thr_find_thread.c @@ -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); |