From 0d5af07a7e14550a70a77a954e9f86eba9848f64 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Tue, 10 Jun 2014 16:27:19 +0200 Subject: [PATCH] fix memory leaks --- coreapi/bellesip_sal/sal_impl.c | 8 +++++--- coreapi/bellesip_sal/sal_op_call.c | 1 + coreapi/bellesip_sal/sal_op_impl.c | 2 +- coreapi/callbacks.c | 6 +++++- coreapi/event.c | 20 ++++++++++++++++++-- tester/call_tester.c | 24 +++++++++++++++++------- tester/message_tester.c | 5 +++-- 7 files changed, 50 insertions(+), 16 deletions(-) diff --git a/coreapi/bellesip_sal/sal_impl.c b/coreapi/bellesip_sal/sal_impl.c index 224bd73ee..c4809ecc6 100644 --- a/coreapi/bellesip_sal/sal_impl.c +++ b/coreapi/bellesip_sal/sal_impl.c @@ -97,14 +97,13 @@ void sal_disable_logs() { void sal_add_pending_auth(Sal *sal, SalOp *op){ if (ms_list_find(sal->pending_auths,op)==NULL){ - sal->pending_auths=ms_list_append(sal->pending_auths,sal_op_ref(op)); + sal->pending_auths=ms_list_append(sal->pending_auths,op); } } void sal_remove_pending_auth(Sal *sal, SalOp *op){ if (ms_list_find(sal->pending_auths,op)){ sal->pending_auths=ms_list_remove(sal->pending_auths,op); - sal_op_unref(op); } } @@ -157,7 +156,10 @@ void sal_process_authentication(SalOp *op) { } } /*always store auth info, for case of wrong credential*/ - if (op->auth_info) sal_auth_info_delete(op->auth_info); + if (op->auth_info) { + sal_auth_info_delete(op->auth_info); + op->auth_info=NULL; + } if (auth_list){ auth_event=(belle_sip_auth_event_t*)(auth_list->data); op->auth_info=sal_auth_info_create(auth_event); diff --git a/coreapi/bellesip_sal/sal_op_call.c b/coreapi/bellesip_sal/sal_op_call.c index f2363af83..26bbdb038 100644 --- a/coreapi/bellesip_sal/sal_op_call.c +++ b/coreapi/bellesip_sal/sal_op_call.c @@ -167,6 +167,7 @@ static void cancelling_invite(SalOp* op ){ sal_op_send_request(op,cancel); op->state=SalOpStateTerminating; } + static int vfu_retry (void *user_data, unsigned int events) { SalOp *op=(SalOp *)user_data; sal_call_send_vfu_request(op); diff --git a/coreapi/bellesip_sal/sal_op_impl.c b/coreapi/bellesip_sal/sal_op_impl.c index 1a49cd65c..649a4e240 100644 --- a/coreapi/bellesip_sal/sal_op_impl.c +++ b/coreapi/bellesip_sal/sal_op_impl.c @@ -44,8 +44,8 @@ void sal_op_release(SalOp *op){ void sal_op_release_impl(SalOp *op){ ms_message("Destroying op [%p] of type [%s]",op,sal_op_type_to_string(op->type)); if (op->pending_auth_transaction) belle_sip_object_unref(op->pending_auth_transaction); + sal_remove_pending_auth(op->base.root,op); if (op->auth_info) { - sal_remove_pending_auth(op->base.root,op); sal_auth_info_delete(op->auth_info); } if (op->sdp_answer) belle_sip_object_unref(op->sdp_answer); diff --git a/coreapi/callbacks.c b/coreapi/callbacks.c index 16b2b9d92..121291a00 100644 --- a/coreapi/callbacks.c +++ b/coreapi/callbacks.c @@ -817,7 +817,11 @@ static void call_released(SalOp *op){ LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op); if (call!=NULL){ linphone_call_set_state(call,LinphoneCallReleased,"Call released"); - }else ms_error("call_released() for already destroyed call ?"); + }else{ + /*we can arrive here when the core manages call at Sal level without creating a LinphoneCall object. Typicially: + * - when declining an incoming call with busy because maximum number of calls is reached. + */ + } } static void auth_failure(SalOp *op, SalAuthInfo* info) { diff --git a/coreapi/event.c b/coreapi/event.c index b1c7b110d..992d058ab 100644 --- a/coreapi/event.c +++ b/coreapi/event.c @@ -79,12 +79,15 @@ static LinphoneEvent *linphone_event_new_with_op_base(LinphoneCore *lc, SalOp *o lev->is_out_of_dialog_op=is_out_of_dialog; return lev; } + LinphoneEvent *linphone_event_new_with_op(LinphoneCore *lc, SalOp *op, LinphoneSubscriptionDir dir, const char *name) { return linphone_event_new_with_op_base(lc,op,dir,name,FALSE); } + LinphoneEvent *linphone_event_new_with_out_of_dialog_op(LinphoneCore *lc, SalOp *op, LinphoneSubscriptionDir dir, const char *name) { return linphone_event_new_with_op_base(lc,op,dir,name,TRUE); } + void linphone_event_set_state(LinphoneEvent *lev, LinphoneSubscriptionState state){ LinphoneCore *lc=lev->lc; if (lev->subscription_state!=state){ @@ -107,9 +110,22 @@ void linphone_event_set_publish_state(LinphoneEvent *lev, LinphonePublishState s if (lc->vtable.publish_state_changed){ lc->vtable.publish_state_changed(lev->lc,lev,state); } - if (state==LinphonePublishCleared){ - linphone_event_unref(lev); + switch(state){ + case LinphonePublishCleared: + linphone_event_unref(lev); + break; + case LinphonePublishOk: + case LinphonePublishError: + if (lev->expires==-1) + linphone_event_unref(lev); + break; + case LinphonePublishNone: + case LinphonePublishProgress: + case LinphonePublishExpiring: + /*nothing special to do*/ + break; } + } } diff --git a/tester/call_tester.c b/tester/call_tester.c index 534065a7a..0c1b50392 100644 --- a/tester/call_tester.c +++ b/tester/call_tester.c @@ -246,14 +246,24 @@ static void end_call(LinphoneCoreManager *m1, LinphoneCoreManager *m2){ } static void simple_call(void) { - LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); - LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc"); + belle_sip_object_enable_leak_detector(TRUE); + int begin=belle_sip_object_get_object_count(); + int leaked_objects; + { + LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); + LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc"); - CU_ASSERT_TRUE(call(pauline,marie)); - liblinphone_tester_check_rtcp(marie,pauline); - end_call(marie,pauline); - linphone_core_manager_destroy(marie); - linphone_core_manager_destroy(pauline); + CU_ASSERT_TRUE(call(pauline,marie)); + liblinphone_tester_check_rtcp(marie,pauline); + end_call(marie,pauline); + linphone_core_manager_destroy(marie); + linphone_core_manager_destroy(pauline); + } + leaked_objects=belle_sip_object_get_object_count()-begin; + CU_ASSERT_TRUE(leaked_objects==0); + if (leaked_objects>0){ + belle_sip_object_dump_active_objects(); + } } static void call_with_specified_codec_bitrate(void) { diff --git a/tester/message_tester.c b/tester/message_tester.c index 151505c59..9e9132fa5 100644 --- a/tester/message_tester.c +++ b/tester/message_tester.c @@ -28,7 +28,7 @@ #endif -static char* message_external_body_url; +static char* message_external_body_url=NULL; void text_message_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from_address, const char *message) { stats* counters = get_stats(lc); @@ -52,7 +52,8 @@ void message_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMess linphone_chat_message_start_file_download(message); } else if (linphone_chat_message_get_external_body_url(message)) { counters->number_of_LinphoneMessageExtBodyReceived++; - CU_ASSERT_STRING_EQUAL(linphone_chat_message_get_external_body_url(message),message_external_body_url); + if (message_external_body_url) + CU_ASSERT_STRING_EQUAL(linphone_chat_message_get_external_body_url(message),message_external_body_url); } }