]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Rearrange _thread_test_func to please Coverity Scan
authorNick Mathewson <nickm@torproject.org>
Mon, 25 Jan 2010 19:12:37 +0000 (14:12 -0500)
committerNick Mathewson <nickm@torproject.org>
Mon, 25 Jan 2010 19:12:37 +0000 (14:12 -0500)
I believe  that since  we were allocating  *cp while holding  a mutex,
coverity deduced that  *cp must be protected by  that mutex, and later
flipped out  when we didn't  use it  that way. If  this is so,  we can
solve our problems by moving the *cp = tor_strdup(buf) part outside of
the mutex-protected code.

src/test/test_util.c

index ba0f8cdf2db7345da0d7c84d211e2db2b3212493..ad8d82b4c0b48af3978c4eee750d26a2fd8b378b 100644 (file)
@@ -420,11 +420,12 @@ _thread_test_func(void* _s)
     cp = &_thread2_name;
     count = &t2_count;
   }
-  tor_mutex_acquire(m);
 
   tor_snprintf(buf, sizeof(buf), "%lu", tor_get_thread_id());
   *cp = tor_strdup(buf);
 
+  tor_mutex_acquire(m);
+
   for (i=0; i<10000; ++i) {
     tor_mutex_acquire(_thread_test_mutex);
     strmap_set(_thread_test_strmap, "last to run", *cp);