]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Join pluto's fetching thread instead of detaching it in order to avoid that the leak...
authorTobias Brunner <tobias@strongswan.org>
Tue, 2 Feb 2010 14:17:09 +0000 (15:17 +0100)
committerTobias Brunner <tobias@strongswan.org>
Tue, 2 Feb 2010 14:23:39 +0000 (15:23 +0100)
src/pluto/fetch.c
src/pluto/fetch.h
src/pluto/plutomain.c

index 3c2a66c3051d9174c280fb4ae1199030bbdbb9d4..ecdadb2ebcdcbc66bbe3a10a4615aeabbabbcaac 100644 (file)
@@ -450,6 +450,9 @@ static void* fetch_thread(void *arg)
 {
        struct timespec wait_interval;
 
+       /* the fetching thread is only cancellable while waiting for new events */
+       thread_cancelability(FALSE);
+
        DBG(DBG_CONTROL,
                DBG_log("fetch thread started")
        )
@@ -466,8 +469,11 @@ static void* fetch_thread(void *arg)
                DBG(DBG_CONTROL,
                        DBG_log("next regular crl check in %ld seconds", crl_check_interval)
                )
+
+               thread_cancelability(TRUE);
                status = pthread_cond_timedwait(&fetch_wake_cond, &fetch_wake_mutex
                                                                                , &wait_interval);
+               thread_cancelability(FALSE);
 
                if (status == ETIMEDOUT)
                {
@@ -500,21 +506,33 @@ void init_fetch(void)
        {
 #ifdef THREADS
                thread = thread_create((thread_main_t)fetch_thread, NULL);
-
                if (thread == NULL)
                {
                        plog("fetching thread could not be started");
                }
-               else
-               {
-                       thread->detach(thread);
-               }
 #else   /* !THREADS */
                plog("warning: not compiled with pthread support");
 #endif  /* !THREADS */
        }
 }
 
+/**
+ * Terminates the fetching thread
+ */
+void fetch_finalize(void)
+{
+       if (crl_check_interval > 0)
+       {
+#ifdef THREADS
+               if (thread)
+               {
+                       thread->cancel(thread);
+                       thread->join(thread);
+               }
+#endif
+       }
+}
+
 void free_crl_fetch(void)
 {
    lock_crl_fetch_list("free_crl_fetch");
index a0e52a8f8e0b335af3c2b3688038fda2c926ad8a..e22a9e2b8eb51c5ce7403f8c190d319d0cb800f1 100644 (file)
@@ -63,6 +63,7 @@ extern void wake_fetch_thread(const char *who);
 #define wake_fetch_thread(who)      /* do nothing */
 #endif
 extern void init_fetch(void);
+extern void fetch_finalize(void);
 extern void free_crl_fetch(void);
 extern void free_ocsp_fetch(void);
 extern void add_distribution_point(linked_list_t *points, char* new_point);
index 0471d26a0fa97c791d6d0104ec174bccd8a52419..a1eb50e692e2c4ac16d411e7ed525683bcfef07b 100644 (file)
@@ -750,6 +750,7 @@ void exit_pluto(int status)
        free_preshared_secrets();
        free_remembered_public_keys();
        delete_every_connection();
+       fetch_finalize();           /* stop fetching thread */
        free_crl_fetch();           /* free chain of crl fetch requests */
        free_ocsp_fetch();          /* free chain of ocsp fetch requests */
        free_authcerts();           /* free chain of X.509 authority certificates */
@@ -765,7 +766,7 @@ void exit_pluto(int status)
        free_crypto();
        free_myid();                /* free myids */
        free_events();              /* free remaining events */
-       free_vendorid();                        /* free all vendor id records */
+       free_vendorid();            /* free all vendor id records */
        free_builder();
        delete_lock();
        options->destroy(options);