Ensure thread IDs always start with 1 even if the library is reused
authorTobias Brunner <tobias@strongswan.org>
Sat, 11 Aug 2012 15:30:39 +0000 (17:30 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 13 Aug 2012 09:28:08 +0000 (11:28 +0200)
Within the Android App the library stays loaded in memory and is just
initialized/deinitialized with each connection, the static thread
counter would continuously increase without this patch.

src/libstrongswan/threading/thread.c

index 49a1b84..9ef514e 100644 (file)
@@ -114,7 +114,7 @@ typedef struct {
 /**
  * Next thread ID.
  */
-static u_int next_id = 1;
+static u_int next_id;
 
 /**
  * Mutex to safely access the next thread ID.
@@ -452,6 +452,7 @@ void threads_init()
 
        dummy1 = thread_value_create(NULL);
 
+       next_id = 1;
        main_thread->id = 0;
        main_thread->thread_id = pthread_self();
        current_thread = thread_value_create(NULL);
@@ -482,4 +483,3 @@ void threads_deinit()
        current_thread->destroy(current_thread);
        id_mutex->destroy(id_mutex);
 }
-