From: Corey Farrell Date: Fri, 7 Mar 2014 22:50:40 +0000 (+0000) Subject: chan_sip: Fix deadlock of monlock between unload_module and do_monitor X-Git-Tag: 1.8.27.0-rc1~17 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dbfbcbb1c72d58ffcae457085b0dc31b17f8f62d;p=thirdparty%2Fasterisk.git chan_sip: Fix deadlock of monlock between unload_module and do_monitor Release monlock before calling pthread_join. This ensures do_monitor cannot freeze by locking monlock during module unload. (closes issue ASTERISK-21406) Reported by: Corey Farrell Review: https://reviewboard.asterisk.org/r/3284/ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@410224 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 97acd4cce7..367130c19b 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -32061,12 +32061,16 @@ static int unload_module(void) ast_mutex_lock(&monlock); if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP) && (monitor_thread != AST_PTHREADT_NULL)) { - pthread_cancel(monitor_thread); - pthread_kill(monitor_thread, SIGURG); - pthread_join(monitor_thread, NULL); + pthread_t th = monitor_thread; + monitor_thread = AST_PTHREADT_STOP; + pthread_cancel(th); + pthread_kill(th, SIGURG); + ast_mutex_unlock(&monlock); + pthread_join(th, NULL); + } else { + monitor_thread = AST_PTHREADT_STOP; + ast_mutex_unlock(&monlock); } - monitor_thread = AST_PTHREADT_STOP; - ast_mutex_unlock(&monlock); /* Destroy all the dialogs and free their memory */ i = ao2_iterator_init(dialogs, 0);