diff --git a/libsofia-sip-ua/nua/nua.c b/libsofia-sip-ua/nua/nua.c index 0a1aa54d..54e7fdef 100644 --- a/libsofia-sip-ua/nua/nua.c +++ b/libsofia-sip-ua/nua/nua.c @@ -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) { @@ -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); } }