diff options
author | Tobias Brunner <tobias@strongswan.org> | 2010-02-02 15:17:09 +0100 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2010-02-02 15:23:39 +0100 |
commit | dc5969242fb521569c82993caeb30ff7e27c8ec3 (patch) | |
tree | 03f65ae555e1221f8550d22b0e0902bc7c1c1f30 /src | |
parent | b7fd2ea76cfc41a771c832978208880350a1d577 (diff) | |
download | strongswan-dc5969242fb521569c82993caeb30ff7e27c8ec3.tar.bz2 strongswan-dc5969242fb521569c82993caeb30ff7e27c8ec3.tar.xz |
Join pluto's fetching thread instead of detaching it in order to avoid that the leak-detective reports a memleak.
Diffstat (limited to 'src')
-rw-r--r-- | src/pluto/fetch.c | 28 | ||||
-rw-r--r-- | src/pluto/fetch.h | 1 | ||||
-rw-r--r-- | src/pluto/plutomain.c | 3 |
3 files changed, 26 insertions, 6 deletions
diff --git a/src/pluto/fetch.c b/src/pluto/fetch.c index 3c2a66c30..ecdadb2eb 100644 --- a/src/pluto/fetch.c +++ b/src/pluto/fetch.c @@ -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"); diff --git a/src/pluto/fetch.h b/src/pluto/fetch.h index a0e52a8f8..e22a9e2b8 100644 --- a/src/pluto/fetch.h +++ b/src/pluto/fetch.h @@ -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); diff --git a/src/pluto/plutomain.c b/src/pluto/plutomain.c index 0471d26a0..a1eb50e69 100644 --- a/src/pluto/plutomain.c +++ b/src/pluto/plutomain.c @@ -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); |