From 81fff857c5455167d807179ff5621d62d9a137f8 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Mon, 7 Jun 2021 20:46:58 +0300 Subject: [PATCH] [mod_sofia] sofia_process_dispatch_event() should unref all handles via sofia stack --- src/mod/endpoints/mod_sofia/mod_sofia.c | 2 +- src/mod/endpoints/mod_sofia/mod_sofia.h | 2 +- src/mod/endpoints/mod_sofia/sofia.c | 20 +++++++------------- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index ce9d520ba8..79a3c06795 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -1343,7 +1343,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi de->session = session; } - sofia_process_dispatch_event(&de, SWITCH_FALSE); + sofia_process_dispatch_event(&de); switch_mutex_unlock(tech_pvt->sofia_mutex); diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index e91d849913..02128bf2fd 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -1253,7 +1253,7 @@ uint32_t sofia_presence_get_cseq(sofia_profile_t *profile); void sofia_glue_build_vid_refresh_message(switch_core_session_t *session, const char *pl); char *sofia_glue_gen_contact_str(sofia_profile_t *profile, sip_t const *sip, nua_handle_t *nh, sofia_dispatch_event_t *de, sofia_nat_parse_t *np); void sofia_glue_pause_jitterbuffer(switch_core_session_t *session, switch_bool_t on); -void sofia_process_dispatch_event(sofia_dispatch_event_t **dep, switch_bool_t stack_thread); +void sofia_process_dispatch_event(sofia_dispatch_event_t **dep); void sofia_process_dispatch_event_in_thread(sofia_dispatch_event_t **dep); char *sofia_glue_get_host(const char *str, switch_memory_pool_t *pool); void sofia_presence_check_subscriptions(sofia_profile_t *profile, time_t now); diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index d152a12810..9ebd0ee35f 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -2230,7 +2230,7 @@ void *SWITCH_THREAD_FUNC sofia_msg_thread_run_once(switch_thread_t *thread, void if (de) { pool = de->pool; de->pool = NULL; - sofia_process_dispatch_event(&de, SWITCH_FALSE); + sofia_process_dispatch_event(&de); } if (pool) { @@ -2263,7 +2263,7 @@ void sofia_process_dispatch_event_in_thread(sofia_dispatch_event_t **dep) switch_thread_pool_launch_thread(&td); } -void sofia_process_dispatch_event(sofia_dispatch_event_t **dep, switch_bool_t stack_thread) +void sofia_process_dispatch_event(sofia_dispatch_event_t **dep) { sofia_dispatch_event_t *de = *dep; nua_handle_t *nh = de->nh; @@ -2282,15 +2282,9 @@ void sofia_process_dispatch_event(sofia_dispatch_event_t **dep, switch_bool_t st profile->queued_events--; switch_mutex_unlock(profile->flag_mutex); - if (stack_thread) { - /* Safe to unref directly */ - if (nh) nua_handle_unref(nh); - nua_unref(nua); - } else { - /* This is not a stack thread, need to call via stack (_user) using events */ - if (nh) nua_handle_unref_user(nh); - nua_unref_user(nua); - } + /* This is not a stack thread, need to call via stack (_user) using events */ + if (nh) nua_handle_unref_user(nh); + nua_unref_user(nua); } @@ -2327,7 +2321,7 @@ void *SWITCH_THREAD_FUNC sofia_msg_thread_run(switch_thread_t *thread, void *obj if (pop) { sofia_dispatch_event_t *de = (sofia_dispatch_event_t *) pop; - sofia_process_dispatch_event(&de, SWITCH_FALSE); + sofia_process_dispatch_event(&de); } else { break; } @@ -2382,7 +2376,7 @@ void sofia_queue_message(sofia_dispatch_event_t *de) if (mod_sofia_globals.running == 0 || !mod_sofia_globals.msg_queue) { /* Calling with SWITCH_TRUE as we are sure this is the stack's thread */ - sofia_process_dispatch_event(&de, SWITCH_TRUE); + sofia_process_dispatch_event(&de); return; }