Skip to content

Commit

Permalink
Merge pull request freeswitch#73 from freeswitch/shutdownleak
Browse files Browse the repository at this point in the history
Fix leaking handles on nua shutdown.
  • Loading branch information
andywolk authored Jun 14, 2021
2 parents 81e9ea7 + 4ff1fb6 commit c20ea78
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions libsofia-sip-ua/nua/nua.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ void nua_shutdown(nua_t *nua)
*/
void nua_destroy(nua_t *nua)
{
nua_handle_t *nh, *nh_next;
enter;

if (nua) {
Expand All @@ -234,6 +235,24 @@ void nua_destroy(nua_t *nua)
#if HAVE_SMIME /* Start NRC Boston */
sm_destroy(nua->sm);
#endif /* End NRC Boston */

/* Cleanup remaining nua handles as they are su_home_new'ed and not su_home_cloned (do not belong to the nua's home)
See nh_create_handle().
*/
for (nh = nua->nua_handles; nh; nh = nh_next) {
su_home_t *nh_home = (su_home_t *)nh;
nh_next = nh->nh_next;

/* at least one handle will be found here and it is nua default handle
which is su_home_cloned (see nua_stack_init()) and therefore does not actually require to be unrefed
but it is safe to do that anyways just for sure
*/
SU_DEBUG_9(("nua(%p): found handle with refcount = "MOD_ZU". Destroying.\n", (void *)nh, su_home_refcount(nh_home)));

/* nua is about to die so we don't remove nh from nua, just unref nh */
while(!su_home_unref(nh_home));
}

nua_unref(nua);
}
}
Expand Down

0 comments on commit c20ea78

Please sign in to comment.