Create a dummy pthread key for value "0", as some buggy PKCS#11 libraries mangle it
authorMartin Willi <martin@revosec.ch>
Wed, 7 Dec 2011 10:29:13 +0000 (11:29 +0100)
committerMartin Willi <martin@revosec.ch>
Wed, 7 Dec 2011 12:42:07 +0000 (13:42 +0100)
src/libstrongswan/threading/thread.c

index 5b6f0d2..d3da1e3 100644 (file)
@@ -414,12 +414,20 @@ void thread_exit(void *val)
 }
 
 /**
+ * A dummy thread value that reserved pthread_key_t value "0". A buggy PKCS#11
+ * library mangles this key, without owning it, so we allocate it for them.
+ */
+static thread_value_t *dummy1;
+
+/**
  * Described in header.
  */
 void threads_init()
 {
        private_thread_t *main_thread = thread_create_internal();
 
+       dummy1 = thread_value_create(NULL);
+
        main_thread->id = 0;
        main_thread->thread_id = pthread_self();
        current_thread = thread_value_create(NULL);
@@ -443,6 +451,8 @@ void threads_deinit()
 {
        private_thread_t *main_thread = (private_thread_t*)thread_current();
 
+       dummy1->destroy(dummy1);
+
        main_thread->mutex->lock(main_thread->mutex);
        thread_destroy(main_thread);
        current_thread->destroy(current_thread);