From aff1134b38c23eccadc4ee40c7cba7b10b6d04ef Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Wed, 9 Feb 2011 22:43:21 +0100 Subject: [PATCH] fix memory leak with call logs for early failed calls, and possible double free in case of error reporting for ended calls --- coreapi/linphonecall.c | 13 +++++++++++++ coreapi/private.h | 1 + 2 files changed, 14 insertions(+) diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index 8e92103d9..d3935700d 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -145,6 +145,7 @@ static void linphone_call_init_common(LinphoneCall *call, LinphoneAddress *from, call->start_time=time(NULL); call->media_start_time=0; call->log=linphone_call_log_new(call, from, to); + call->owns_call_log=TRUE; linphone_core_notify_all_friends(call->core,LinphoneStatusOnThePhone); port_offset=find_port_offset (call->core); if (port_offset==-1) return; @@ -241,8 +242,10 @@ static void linphone_call_set_terminated(LinphoneCall *call){ else status=LinphoneCallSuccess; } + call->owns_call_log=FALSE; linphone_call_log_completed(call->log,call, status); + if (call == lc->current_call){ ms_message("Resetting the current call"); lc->current_call=NULL; @@ -305,6 +308,13 @@ void linphone_call_set_state(LinphoneCall *call, LinphoneCallState cstate, const LinphoneCore *lc=call->core; if (call->state!=cstate){ + if (call->state==LinphoneCallEnd || call->state==LinphoneCallError){ + if (cstate!=LinphoneCallReleased){ + ms_warning("Spurious call state change from %s to %s, ignored.",linphone_call_state_to_string(call->state), + linphone_call_state_to_string(cstate)); + return; + } + } ms_message("Call %p: moving from state %s to %s",call,linphone_call_state_to_string(call->state), linphone_call_state_to_string(cstate)); if (cstate!=LinphoneCallRefered){ @@ -315,6 +325,7 @@ void linphone_call_set_state(LinphoneCall *call, LinphoneCallState cstate, const if (cstate==LinphoneCallEnd || cstate==LinphoneCallError){ linphone_call_set_terminated (call); } + if (lc->vtable.call_state_changed) lc->vtable.call_state_changed(lc,call,cstate,message); if (cstate==LinphoneCallReleased){ @@ -349,6 +360,8 @@ static void linphone_call_destroy(LinphoneCall *obj) if (obj->refer_to){ ms_free(obj->refer_to); } + if (obj->owns_call_log) + linphone_call_log_destroy(obj->log); ms_free(obj); } diff --git a/coreapi/private.h b/coreapi/private.h index 17754c289..838d6a132 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -98,6 +98,7 @@ struct _LinphoneCall bool_t camera_active; bool_t all_muted; /*this flag is set during early medias*/ bool_t playing_ringbacktone; + bool_t owns_call_log; };