From 99fbff408e42931f9a30e32ef94d07d87d5cbe64 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Fri, 30 Jul 2021 20:23:10 -0400 Subject: [PATCH] TT#14008 fix call iterator dead lock ... almost there ... Change-Id: I3261ec91ac7481bb275bbb4f9841747938706e61 --- daemon/call.c | 3 ++- include/call.h | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/daemon/call.c b/daemon/call.c index 2923ca59b..028c0573d 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -2851,7 +2851,8 @@ void call_destroy(struct call *c) { } if (next_call) { if (mutex_trylock(&next_call->iterator[i].prev_lock)) { - mutex_unlock(&prev_call->iterator[i].next_lock); + if (prev_call) + mutex_unlock(&prev_call->iterator[i].next_lock); mutex_unlock(&c->iterator[i].next_lock); mutex_unlock(&c->iterator[i].prev_lock); mutex_unlock(&rtpe_call_iterators[i].lock); diff --git a/include/call.h b/include/call.h index f1fb4344c..21a78c714 100644 --- a/include/call.h +++ b/include/call.h @@ -437,6 +437,7 @@ struct call_iterator_entry { mutex_lock(&rtpe_call_iterators[__which].lock); \ \ GList *__l = rtpe_call_iterators[__which].first; \ + bool __has_lock = true; \ struct call *next_ ## varname = NULL; \ while (__l) { \ struct call *varname = NULL; \ @@ -447,7 +448,9 @@ struct call_iterator_entry { obj_hold(varname); \ mutex_lock(&varname->iterator[__which].next_lock); \ } \ - mutex_unlock(&rtpe_call_iterators[__which].lock) + if (__has_lock) \ + mutex_unlock(&rtpe_call_iterators[__which].lock); \ + __has_lock = false #define ITERATE_CALL_LIST_NEXT_END(varname) \ GList *__next = varname->iterator[__which].link.next; \ @@ -461,10 +464,9 @@ struct call_iterator_entry { mutex_unlock(&varname->iterator[__which].next_lock); \ __l = __next; \ obj_put(varname); \ - mutex_lock(&rtpe_call_iterators[__which].lock); \ } \ - \ - mutex_unlock(&rtpe_call_iterators[__which].lock); \ + if (__has_lock) \ + mutex_unlock(&rtpe_call_iterators[__which].lock); \ } while (0) struct call {