From 7d2248f38a4f3deac5a50e4b645c7e0c3f6d0136 Mon Sep 17 00:00:00 2001 From: Nanang Izzuddin Date: Wed, 6 Mar 2024 12:21:34 +0700 Subject: [PATCH] Add checks in restarting listeners in IP change scenario (#3872) --- pjsip/src/pjsua-lib/pjsua_core.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/pjsip/src/pjsua-lib/pjsua_core.c b/pjsip/src/pjsua-lib/pjsua_core.c index 66cb8c9da3..901777752b 100644 --- a/pjsip/src/pjsua-lib/pjsua_core.c +++ b/pjsip/src/pjsua-lib/pjsua_core.c @@ -3845,12 +3845,22 @@ static pj_status_t restart_listener(pjsua_transport_id id, pj_sockaddr bind_addr; pjsua_transport_info tp_info; pj_status_t status; + pj_bool_t tp_valid = PJ_TRUE; + pj_uint16_t saf; - pjsua_transport_get_info(id, &tp_info); + status = pjsua_transport_get_info(id, &tp_info); + if (status != PJ_SUCCESS) { + /* Transport not valid or already destroyed */ + tp_valid = PJ_FALSE; + goto on_return; + } + + saf = tp_info.local_addr.addr.sa_family; pj_sockaddr_init(pjsip_transport_type_get_af(tp_info.type), - &bind_addr, - NULL, - pj_sockaddr_get_port(&tp_info.local_addr)); + &bind_addr, + NULL, + (saf==PJ_AF_INET || saf==PJ_AF_INET6)? + pj_sockaddr_get_port(&tp_info.local_addr) : 0); switch (tp_info.type) { case PJSIP_TRANSPORT_UDP: @@ -3899,7 +3909,9 @@ static pj_status_t restart_listener(pjsua_transport_id id, PJ_PERROR(3,(THIS_FILE, status, "Listener %.*s restart", (int)tp_info.info.slen, tp_info.info.ptr)); - if (status != PJ_SUCCESS && (restart_lis_delay > 0)) { +on_return: + + if (tp_valid && status != PJ_SUCCESS && (restart_lis_delay > 0)) { /* Try restarting again, with delay. */ pjsua_schedule_timer2(&restart_listener_cb, (void*)(pj_size_t)id, @@ -3993,15 +4005,15 @@ PJ_DEF(pj_status_t) pjsua_handle_ip_change(const pjsua_ip_change_param *param) /* Shutdown all TCP/TLS transports */ if (param->shutdown_transport) { - pjsip_tpmgr_shutdown_param param; + pjsip_tpmgr_shutdown_param sd_param; - pjsip_tpmgr_shutdown_param_default(¶m); - param.include_udp = PJ_FALSE; + pjsip_tpmgr_shutdown_param_default(&sd_param); + sd_param.include_udp = PJ_FALSE; PJ_LOG(4,(THIS_FILE, "IP change shutting down transports..")); status = pjsip_tpmgr_shutdown_all( pjsip_endpt_get_tpmgr(pjsua_var.endpt), - ¶m); + &sd_param); /* Provide dummy info instead of NULL info to avoid possible crash * (if app does not check).