[tor-commits] [tor/master] don't init threads as side effect of assertion

nickm at torproject.org nickm at torproject.org
Fri Mar 13 13:41:56 UTC 2015


commit 68e9f364a01fa8efadd06745d2e54d699996646a
Author: Sebastian Hahn <sebastian at torproject.org>
Date:   Thu Mar 12 17:52:37 2015 +0100

    don't init threads as side effect of assertion
    
    Fixes part of bug 15211.
---
 changes/bug15211             |    5 +++++
 src/common/compat_pthreads.c |    8 +++++---
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/changes/bug15211 b/changes/bug15211
new file mode 100644
index 0000000..b99e61e
--- /dev/null
+++ b/changes/bug15211
@@ -0,0 +1,5 @@
+  o Minor bugfixes:
+    - Remove side-effects from tor_assert() calls. This was harmless,
+      because we never disable assertions, but it is bad style and
+      unnecessary. Fixes bug 15211; bugfix on 0.2.5.5.
+
diff --git a/src/common/compat_pthreads.c b/src/common/compat_pthreads.c
index 246076b..70259a8 100644
--- a/src/common/compat_pthreads.c
+++ b/src/common/compat_pthreads.c
@@ -276,14 +276,16 @@ void
 tor_threads_init(void)
 {
   if (!threads_initialized) {
+    int ret;
     pthread_mutexattr_init(&attr_recursive);
     pthread_mutexattr_settype(&attr_recursive, PTHREAD_MUTEX_RECURSIVE);
-    tor_assert(0==pthread_attr_init(&attr_detached));
+    ret = pthread_attr_init(&attr_detached);
+    tor_assert(ret == 0);
 #ifndef PTHREAD_CREATE_DETACHED
 #define PTHREAD_CREATE_DETACHED 1
 #endif
-    tor_assert(0==pthread_attr_setdetachstate(&attr_detached,
-                                              PTHREAD_CREATE_DETACHED));
+    ret = pthread_attr_setdetachstate(&attr_detached, PTHREAD_CREATE_DETACHED);
+    tor_assert(ret == 0);
     threads_initialized = 1;
     set_main_thread();
   }





More information about the tor-commits mailing list