Hi,

The gl_recursive_lock_init() macro used for the pthread backend never
set the mutex attribute to be recursive. The end result is that a
'standard' mutex is created, which will deadlock on recursive use. A
patch is attached that fixes this issue.

Additionally, lock.h make use of the abort() function, which can be a
problem if the application / library handle pthread error in a specific
way. Is that done on purpose, or are you interested in a patch?

Regards,

-- 
Yoann Vandoorselaere | Responsable R&D / CTO | PreludeIDS Technologies
Tel: +33 (0)8 70 70 21 58                  Fax: +33(0)4 78 42 21 58
http://www.prelude-ids.com
diff --git a/lib/lock.h b/lib/lock.h
index 3f0da52..04d98e0 100644
--- a/lib/lock.h
+++ b/lib/lock.h
@@ -361,11 +361,26 @@ typedef pthread_mutex_t gl_recursive_lock_t;
        PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
 #   endif
 #   define gl_recursive_lock_init(NAME) \
-      do                                                                  \
-        {                                                                 \
-          if (pthread_in_use () && pthread_mutex_init (&NAME, NULL) != 0) \
-            abort ();                                                     \
-        }                                                                 \
+      do                                                                         \
+        {                                                                        \
+          pthread_mutexattr_t mattr;                                             \
+                                                                                 \
+          if ( ! pthread_in_use() )                                              \
+            return 0;                                                            \
+                                                                                 \
+          if (pthread_mutexattr_init (&mattr) != 0)                              \
+            abort ();                                                            \
+                                                                                 \
+          if (pthread_mutexattr_settype(&mattr, PTHREAD_MUTEX_RECURSIVE) != 0) { \
+            pthread_mutexattr_destroy(&mattr);                                   \
+            abort ();                                                            \
+          }                                                                      \
+                                                                                 \
+          if (pthread_mutex_init (&NAME, &mattr) != 0)                           \
+            abort ();                                                            \
+                                                                                 \
+          pthread_mutexattr_destroy(&mattr);                                     \
+        }                                                                        \
       while (0)
 #   define gl_recursive_lock_lock(NAME) \
       do                                                            \

Reply via email to