From 9eb20d7b54a1abf77ecef37b45ab25d08e49a0fe Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Mon, 30 Aug 2021 09:44:26 +0000 Subject: [PATCH] [mod_sofia] fix memleak on gw registration timeout or 403 --- src/mod/endpoints/mod_sofia/sofia.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index a752a4a8f4..4af8d3d451 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -3500,10 +3500,24 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void } } - /* Do gateway cleanups */ + /* Gateway cleanup start */ + /* Mark all gateways as deleted and set REG_STATE_UNREGISTER state on REG gateways */ sofia_glue_del_every_gateway(profile); + /* First call will unregister and set state to DOWN so a gateway is ready for deletion */ sofia_reg_check_gateway(profile, switch_epoch_time_now(NULL)); sofia_sub_check_gateway(profile, switch_epoch_time_now(NULL)); + /* + * The gateway life cycle requires a gateway to go though different states before it's destroyed. + * Normally sofia_reg_check_gateway() is called periodically + * but it's not the case on profile shutdown. + * + * All REG gateways should be DOWN now and can be finally deleted. + * Calling sofia_reg_check_gateway() second time. + */ + sofia_reg_check_gateway(profile, switch_epoch_time_now(NULL)); + sofia_sub_check_gateway(profile, switch_epoch_time_now(NULL)); + /* Gateway cleanup end */ + sofia_glue_fire_events(profile); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Waiting for worker thread\n");