From 10859adfd4268a819766b436e9b5f40bc69c54bb Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 21 Jul 2014 11:35:34 +0200 Subject: [PATCH] stream-service: Do not accept or re-register when service is terminated --- .../networking/streams/stream_service.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libstrongswan/networking/streams/stream_service.c b/src/libstrongswan/networking/streams/stream_service.c index 07d9cfdef1..6ce37e8875 100644 --- a/src/libstrongswan/networking/streams/stream_service.c +++ b/src/libstrongswan/networking/streams/stream_service.c @@ -76,6 +76,11 @@ struct private_stream_service_t { * Condvar to wait for callback termination */ condvar_t *condvar; + + /** + * TRUE when the service is terminated + */ + bool terminated; }; /** @@ -105,7 +110,7 @@ static void destroy_async_data(async_data_t *data) private_stream_service_t *this = data->this; this->mutex->lock(this->mutex); - if (this->active-- == this->cncrncy) + if (this->active-- == this->cncrncy && !this->terminated) { /* leaving concurrency limit, restart accept()ing. */ lib->watcher->add(lib->watcher, this->fd, @@ -154,7 +159,7 @@ static bool watch(private_stream_service_t *this, int fd, watcher_event_t event) .this = this, ); - if (data->fd != -1) + if (data->fd != -1 && !this->terminated) { this->mutex->lock(this->mutex); if (++this->active == this->cncrncy) @@ -213,6 +218,9 @@ METHOD(stream_service_t, on_accept, void, METHOD(stream_service_t, destroy, void, private_stream_service_t *this) { + this->mutex->lock(this->mutex); + this->terminated = TRUE; + this->mutex->unlock(this->mutex); on_accept(this, NULL, NULL, this->prio, this->cncrncy); close(this->fd); this->mutex->destroy(this->mutex);