diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 847aab2661..4902bee70e 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -75,7 +75,6 @@ void sofia_handle_sip_r_notify(switch_core_session_t *session, int status, sql = switch_mprintf("delete from sip_subscriptions where call_id='%q'", sip->sip_call_id->i_id); switch_assert(sql != NULL); sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE); - nua_handle_destroy(nh); } } @@ -347,14 +346,18 @@ void sofia_event_callback(nua_event_t event, //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Destroy handle [%s]\n", nua_event_name(event)); if (sofia_private) { nua_handle_bind(nh, NULL); - sofia_private->destroy_me = 1; } nua_handle_destroy(nh); + nh = NULL; } break; } if (sofia_private && sofia_private->destroy_me) { + if (nh) { + nua_handle_bind(nh, NULL); + } + sofia_private->destroy_me = 12; free(sofia_private); sofia_private = NULL; } @@ -1520,6 +1523,7 @@ static void sofia_handle_sip_r_options(switch_core_session_t *session, int statu if (sofia_private && !switch_strlen_zero(sofia_private->gateway_name)) { gateway = sofia_reg_find_gateway(sofia_private->gateway_name); + sofia_private->destroy_me = 1; } if (gateway) { diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index 656284f53a..0f22ffd05a 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -88,7 +88,6 @@ void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now) switch_assert(pvt); memset(pvt, 0, sizeof(*pvt)); pvt->destroy_nh = 1; - pvt->destroy_me = 1; switch_copy_string(pvt->gateway_name, gateway_ptr->name, sizeof(pvt->gateway_name)); nua_handle_bind(nh, pvt);