From d9faf7baf424667acbcb936f935d1ca22ea0eb6b Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Thu, 20 Jul 2017 15:56:46 +0200 Subject: lib: Fix destruction of CDAP instances The received message list was not correctly freed upon destruction of the CDAP object. There was also still a rare case in which thread cancellation would keep a lock, blocking the IPCP shutdown, which is also fixed. --- src/lib/cdap.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/lib/cdap.c b/src/lib/cdap.c index 16f2c078..c1209138 100644 --- a/src/lib/cdap.c +++ b/src/lib/cdap.c @@ -268,7 +268,7 @@ static void cdap_rcvd_destroy(struct cdap * instance) pthread_mutex_lock(&instance->rcvd_lock); - list_for_each_safe(p, h, &instance->sent) { + list_for_each_safe(p, h, &instance->rcvd) { struct cdap_rcvd * r = list_entry(p, struct cdap_rcvd, next); list_del(&r->next); if (r->data != NULL) @@ -578,15 +578,8 @@ int cdap_del_flow(struct cdap * instance, pthread_rwlock_wrlock(&instance->flows_lock); - pthread_mutex_lock(&instance->mtx); - - while (instance->proc) - pthread_cond_wait(&instance->cond, &instance->mtx); - flow_set_del(instance->set, fd); - pthread_mutex_unlock(&instance->mtx); - list_for_each_safe(p, h, &instance->flows) { struct fd_el * e = list_entry(p, struct fd_el, next); if (e->fd == fd) { @@ -600,6 +593,16 @@ int cdap_del_flow(struct cdap * instance, pthread_rwlock_unlock(&instance->flows_lock); + pthread_mutex_lock(&instance->mtx); + + pthread_cleanup_push((void(*)(void *))pthread_mutex_unlock, + (void *) &instance->mtx); + + while (instance->proc) + pthread_cond_wait(&instance->cond, &instance->mtx); + + pthread_cleanup_pop(true); + return 0; } -- cgit v1.2.3