From e4d97e2a5171b7b2bec50dc53bd66ac6f5f7b1c3 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Tue, 5 Jan 2016 21:14:18 +0100 Subject: [PATCH] add release methods for friends and friend list, so that the core can properly shutdown without leaving references. --- coreapi/friend.c | 13 ++++++++++++- coreapi/friendlist.c | 8 ++++++++ coreapi/linphonecore.c | 4 ++-- coreapi/private.h | 2 ++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/coreapi/friend.c b/coreapi/friend.c index fa4a3f18c..1c11ab21a 100644 --- a/coreapi/friend.c +++ b/coreapi/friend.c @@ -265,12 +265,16 @@ void linphone_friend_close_subscriptions(LinphoneFriend *lf){ lf->insubs = ms_list_free_with_data(lf->insubs, (MSIterateFunc)sal_op_release); } -static void _linphone_friend_destroy(LinphoneFriend *lf){ +static void _linphone_friend_release_ops(LinphoneFriend *lf){ lf->insubs = ms_list_free_with_data(lf->insubs, (MSIterateFunc) sal_op_release); if (lf->outsub){ sal_op_release(lf->outsub); lf->outsub=NULL; } +} + +static void _linphone_friend_destroy(LinphoneFriend *lf){ + _linphone_friend_release_ops(lf); if (lf->presence != NULL) linphone_presence_model_unref(lf->presence); if (lf->uri!=NULL) linphone_address_destroy(lf->uri); if (lf->info!=NULL) buddy_info_free(lf->info); @@ -712,6 +716,13 @@ void linphone_friend_destroy(LinphoneFriend *lf) { linphone_friend_unref(lf); } +/*drops all references to the core and unref*/ +void _linphone_friend_release(LinphoneFriend *lf){ + lf->lc = NULL; + _linphone_friend_release_ops(lf); + linphone_friend_unref(lf); +} + BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneFriend); BELLE_SIP_INSTANCIATE_VPTR(LinphoneFriend, belle_sip_object_t, diff --git a/coreapi/friendlist.c b/coreapi/friendlist.c index e620dba08..e82946a0f 100644 --- a/coreapi/friendlist.c +++ b/coreapi/friendlist.c @@ -250,6 +250,14 @@ LinphoneFriendList * linphone_friend_list_ref(LinphoneFriendList *list) { return list; } +void _linphone_friend_list_release(LinphoneFriendList *list){ + /*drops all references to core and unref*/ + list->lc = NULL; + if (list->event != NULL) linphone_event_unref(list->event); + list->friends = ms_list_free_with_data(list->friends, (void (*)(void *))_linphone_friend_release); + belle_sip_object_unref(list); +} + void linphone_friend_list_unref(LinphoneFriendList *list) { belle_sip_object_unref(list); } diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 2e1e8b87f..113c708cd 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -6352,10 +6352,10 @@ static void codecs_config_uninit(LinphoneCore *lc) void ui_config_uninit(LinphoneCore* lc) { ms_message("Destroying friends."); - linphone_friend_list_unref(lc->friendlist); + _linphone_friend_list_release(lc->friendlist); lc->friendlist = NULL; if (lc->subscribers){ - lc->subscribers = ms_list_free_with_data(lc->subscribers, (void (*)(void *))linphone_friend_unref); + lc->subscribers = ms_list_free_with_data(lc->subscribers, (void (*)(void *))_linphone_friend_release); } if (lc->presence_model) { linphone_presence_model_unref(lc->presence_model); diff --git a/coreapi/private.h b/coreapi/private.h index ebc1618f8..ca1fd76f7 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -393,8 +393,10 @@ const LinphoneAddress* linphone_proxy_config_get_service_route(const LinphonePro void linphone_friend_list_invalidate_subscriptions(LinphoneFriendList *list); void linphone_friend_list_notify_presence_received(LinphoneFriendList *list, LinphoneEvent *lev, const LinphoneContent *body); +void _linphone_friend_list_release(LinphoneFriendList *list); void linphone_friend_invalidate_subscription(LinphoneFriend *lf); void linphone_friend_close_subscriptions(LinphoneFriend *lf); +void _linphone_friend_release(LinphoneFriend *lf); void linphone_friend_update_subscribes(LinphoneFriend *fr, LinphoneProxyConfig *cfg, bool_t only_when_registered); void linphone_friend_notify(LinphoneFriend *lf, LinphonePresenceModel *presence); void linphone_friend_add_incoming_subscription(LinphoneFriend *lf, SalOp *op);