Commit 73cfad32 authored by Simon Morlat's avatar Simon Morlat
Browse files

fix memory leaks around presence

parent a9d34e7b
......@@ -47,7 +47,7 @@ void sal_add_presence_info(SalOp *op, belle_sip_message_t *notify, SalPresenceMo
}
static void presence_process_io_error(void *user_ctx, const belle_sip_io_error_event_t *event){
ms_error("presence_process_io_error not implemented yet");
/*ms_error("presence_process_io_error not implemented yet");*/
}
static void presence_process_dialog_terminated(void *ctx, const belle_sip_dialog_terminated_event_t *event) {
......
......@@ -290,6 +290,17 @@ static void _linphone_friend_destroy(LinphoneFriend *lf){
if (lf->info!=NULL) buddy_info_free(lf->info);
}
static belle_sip_error_code _linphone_friend_marshall(belle_sip_object_t *obj, char* buff, size_t buff_size, size_t *offset) {
LinphoneFriend *lf = (LinphoneFriend*)obj;
belle_sip_error_code err = BELLE_SIP_OK;
if (lf->uri){
char *tmp = linphone_address_as_string(lf->uri);
err = belle_sip_snprintf(buff, buff_size, offset, "%s", tmp);
ms_free(tmp);
}
return err;
}
const LinphoneAddress *linphone_friend_get_address(const LinphoneFriend *lf){
return lf->uri;
}
......@@ -491,6 +502,11 @@ void linphone_core_add_friend(LinphoneCore *lc, LinphoneFriend *lf)
return ;
}
lc->friends=ms_list_append(lc->friends,linphone_friend_ref(lf));
if (ms_list_find(lc->subscribers, lf)){
/*if this friend was in the pending subscriber list, now remove it from this list*/
lc->subscribers = ms_list_remove(lc->subscribers, lf);
linphone_friend_unref(lf);
}
lf->lc=lc;
if ( linphone_core_ready(lc)) linphone_friend_apply(lf,lc);
else lf->commit=TRUE;
......@@ -500,7 +516,7 @@ void linphone_core_add_friend(LinphoneCore *lc, LinphoneFriend *lf)
void linphone_core_remove_friend(LinphoneCore *lc, LinphoneFriend* fl){
MSList *el=ms_list_find(lc->friends,fl);
if (el!=NULL){
linphone_friend_destroy((LinphoneFriend*)el->data);
linphone_friend_unref((LinphoneFriend*)el->data);
lc->friends=ms_list_remove_link(lc->friends,el);
linphone_core_write_friends_config(lc);
}else{
......@@ -713,6 +729,6 @@ BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneFriend);
BELLE_SIP_INSTANCIATE_VPTR(LinphoneFriend, belle_sip_object_t,
(belle_sip_object_destroy_t) _linphone_friend_destroy,
NULL, // clone
NULL, // marshal
_linphone_friend_marshall,
FALSE
);
\ No newline at end of file
......@@ -6427,9 +6427,6 @@ static void linphone_core_uninit(LinphoneCore *lc)
if (lc->chat_db_file){
ms_free(lc->chat_db_file);
}
if(lc->presence_model){
linphone_presence_model_unref(lc->presence_model);
}
linphone_core_free_payload_types(lc);
if (lc->supported_formats) ms_free(lc->supported_formats);
linphone_core_message_storage_close(lc);
......
......@@ -1444,17 +1444,19 @@ static LinphonePresenceModel * process_pidf_xml_presence_notification(xmlparsing
void linphone_core_add_subscriber(LinphoneCore *lc, const char *subscriber, SalOp *op){
LinphoneFriend *fl=linphone_friend_new_with_address(subscriber);
char *tmp;
if (fl==NULL) return ;
linphone_friend_add_incoming_subscription(fl, op);
linphone_friend_set_inc_subscribe_policy(fl,LinphoneSPAccept);
fl->inc_subscribe_pending=TRUE;
lc->subscribers=ms_list_append(lc->subscribers,(void *)linphone_friend_ref(fl));
{
char *tmp=linphone_address_as_string(fl->uri);
linphone_core_notify_new_subscription_requested(lc,fl,tmp);
linphone_friend_unref(fl);
ms_free(tmp);
}
/* the newly created "not yet" friend ownership is transfered to the lc->subscribers list*/
lc->subscribers=ms_list_append(lc->subscribers,fl);
tmp = linphone_address_as_string(fl->uri);
linphone_core_notify_new_subscription_requested(lc,fl,tmp);
ms_free(tmp);
}
void linphone_core_reject_subscriber(LinphoneCore *lc, LinphoneFriend *lf){
......
......@@ -28,12 +28,14 @@ static LinphoneCoreManager* presence_linphone_core_manager_new(char* username) {
linphone_address_set_username(mgr->identity,username);
identity_char=linphone_address_as_string(mgr->identity);
linphone_core_set_primary_contact(mgr->lc,identity_char);
ms_free(identity_char);
return mgr;
}
void new_subscription_requested(LinphoneCore *lc, LinphoneFriend *lf, const char *url){
char* from=linphone_address_as_string(linphone_friend_get_address(lf));
stats* counters;
ms_message("New subscription request from [%s] url [%s]",from,url);
ms_message("New subscription request from [%s] url [%s]",from,url);
ms_free(from);
counters = get_stats(lc);
counters->number_of_NewSubscriptionRequest++;
......@@ -374,6 +376,13 @@ static void subscribe_presence_forked(){
/*we should get two notifies*/
BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphonePresenceActivityOnline,2, 10000));
/*marie also shall receive two SUBSCRIBEs from the two paulines, but won't be notified to the app since
Marie set Pauline as a friend.*/
BC_ASSERT_EQUAL(marie->stat.number_of_NewSubscriptionRequest, 0, int, "%d");
/*and the two paulines shall be notified of marie's presence*/
BC_ASSERT_TRUE(wait_for_list(lcs,&pauline1->stat.number_of_LinphonePresenceActivityOnline,1, 3000));
BC_ASSERT_TRUE(wait_for_list(lcs,&pauline2->stat.number_of_LinphonePresenceActivityOnline,1, 2000));
linphone_core_manager_destroy(marie);
linphone_core_manager_destroy(pauline1);
linphone_core_manager_destroy(pauline2);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment