Skip to content

Commit

Permalink
fix edge case that causes crash when unregistering (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
Elhodred authored Feb 2, 2024
1 parent ade1129 commit 10fe225
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,5 @@ images/test_text.png

src/mod/codecs/mod_amrwb/test/test_amrwb
src/mod/endpoints/mod_sofia/test/sipp-based-tests

DEBBUILD/
16 changes: 8 additions & 8 deletions src/mod/endpoints/mod_sofia/sofia.c
Original file line number Diff line number Diff line change
Expand Up @@ -1515,14 +1515,6 @@ static void our_sofia_event_callback(nua_event_t event,

if (sofia_private && sofia_private != &mod_sofia_globals.destroy_private && sofia_private != &mod_sofia_globals.keep_private) {
if (!zstr(sofia_private->gateway_name)) {
if (event == nua_r_unregister && status != 401 && status != 407) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Destroy handle after unregister for gateway %s.\n", sofia_private->gateway_name);
sofia_private_free(sofia_private);
nua_handle_bind(nh, NULL);
nua_handle_destroy(nh);
nh = NULL;
return;
}
if (!(gateway = sofia_reg_find_gateway(sofia_private->gateway_name))) {
return;
}
Expand Down Expand Up @@ -1633,6 +1625,14 @@ static void our_sofia_event_callback(nua_event_t event,
}
}

if (event == nua_r_unregister && status != 401 && status != 407 && status >= 200) {
if (gateway) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Mark gateway %s for destruction after unregister. Status %d.\n", sofia_private->gateway_name, status);
gateway->destroy = 1;
}
goto done;
}

if (sofia_test_pflag(profile, PFLAG_AUTH_ALL) && tech_pvt && tech_pvt->key && sip && (event < nua_r_set_params || event > nua_r_authenticate)) {
sip_authorization_t const *authorization = NULL;

Expand Down
16 changes: 16 additions & 0 deletions src/mod/endpoints/mod_sofia/sofia_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,22 @@ void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now)
user_via = NULL;
}

if(ostate == REG_STATE_DOWN && gateway_ptr->destroy) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Destroy sofia_private and nua_handler for gateway %s\n", gateway_ptr->name);

if (gateway_ptr->sofia_private) {
sofia_private_free(gateway_ptr->sofia_private);
}

if (gateway_ptr->nh) {
nua_handle_bind(gateway_ptr->nh, NULL);
nua_handle_destroy(gateway_ptr->nh);
gateway_ptr->nh = NULL;
}

gateway_ptr->destroy = 0;
}

switch (ostate) {
case REG_STATE_DOWN:
case REG_STATE_NOREG:
Expand Down

0 comments on commit 10fe225

Please sign in to comment.