From 9c396a9cd943174ed06c5da3fa70fe105666ce34 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Sun, 31 Aug 2014 10:56:37 +0200 Subject: [PATCH] Fix big crash in call logs because logs built from linphonerc were constructed using ms_new0(LinphoneCallLog,1). --- coreapi/call_log.c | 17 ++++++++++------- coreapi/linphonecall.c | 14 ++++++-------- coreapi/linphonecore.c | 6 +++--- coreapi/private.h | 7 +++---- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/coreapi/call_log.c b/coreapi/call_log.c index dd9baa5b7..d1e59578f 100644 --- a/coreapi/call_log.c +++ b/coreapi/call_log.c @@ -104,13 +104,16 @@ void call_logs_read_from_config_file(LinphoneCore *lc){ for(i=0;;++i){ snprintf(logsection,sizeof(logsection),"call_log_%i",i); if (lp_config_has_section(cfg,logsection)){ - LinphoneCallLog *cl=ms_new0(LinphoneCallLog,1); - cl->dir=lp_config_get_int(cfg,logsection,"dir",0); - cl->status=lp_config_get_int(cfg,logsection,"status",0); + LinphoneCallLog *cl; + LinphoneAddress *from=NULL,*to=NULL; tmp=lp_config_get_string(cfg,logsection,"from",NULL); - if (tmp) cl->from=linphone_address_new(tmp); + if (tmp) from=linphone_address_new(tmp); tmp=lp_config_get_string(cfg,logsection,"to",NULL); - if (tmp) cl->to=linphone_address_new(tmp); + if (tmp) to=linphone_address_new(tmp); + if (!from || !to) + continue; + cl=linphone_call_log_new(lp_config_get_int(cfg,logsection,"dir",0),from,to); + cl->status=lp_config_get_int(cfg,logsection,"status",0); sec=lp_config_get_int64(cfg,logsection,"start_date_time",0); if (sec) { /*new call log format with date expressed in seconds */ @@ -266,9 +269,9 @@ static void _linphone_call_log_destroy(LinphoneCallLog *cl){ if (cl->reporting.reports[LINPHONE_CALL_STATS_VIDEO]!=NULL) linphone_reporting_destroy(cl->reporting.reports[LINPHONE_CALL_STATS_VIDEO]); } -LinphoneCallLog * linphone_call_log_new(LinphoneCall *call, LinphoneAddress *from, LinphoneAddress *to){ +LinphoneCallLog * linphone_call_log_new(LinphoneCallDir dir, LinphoneAddress *from, LinphoneAddress *to){ LinphoneCallLog *cl=belle_sip_object_new(LinphoneCallLog); - cl->dir=call->dir; + cl->dir=dir; cl->start_date_time=time(NULL); set_call_log_date(cl,cl->start_date_time); cl->from=from; diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index 79d35357d..4fc12d737 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -573,8 +573,7 @@ static void linphone_call_init_common(LinphoneCall *call, LinphoneAddress *from, call->state=LinphoneCallIdle; call->transfer_state = LinphoneCallIdle; call->media_start_time=0; - call->log=linphone_call_log_new(call, from, to); - call->owns_call_log=TRUE; + call->log=linphone_call_log_new(call->dir, from, to); call->camera_enabled=TRUE; call->current_params.media_encryption=LinphoneMediaEncryptionNone; @@ -864,7 +863,6 @@ static void linphone_call_set_terminated(LinphoneCall *call){ linphone_core_update_allocated_audio_bandwidth(lc); linphone_call_stats_uninit(&call->stats[0]); linphone_call_stats_uninit(&call->stats[1]); - call->owns_call_log=FALSE; linphone_call_log_completed(call); @@ -1041,8 +1039,8 @@ static void linphone_call_destroy(LinphoneCall *obj) if (obj->transfer_target){ linphone_call_unref(obj->transfer_target); } - if (obj->owns_call_log) - linphone_call_log_destroy(obj->log); + if (obj->log) + linphone_call_log_unref(obj->log); if (obj->auth_token) { ms_free(obj->auth_token); } @@ -3114,7 +3112,7 @@ void linphone_call_log_completed(LinphoneCall *call){ lc->vtable.display_status(lc,info); ms_free(info); } - lc->call_logs=ms_list_prepend(lc->call_logs,(void *)call->log); + lc->call_logs=ms_list_prepend(lc->call_logs,linphone_call_log_ref(call->log)); if (ms_list_size(lc->call_logs)>lc->max_call_logs){ MSList *elem,*prevelem=NULL; /*find the last element*/ @@ -3122,7 +3120,7 @@ void linphone_call_log_completed(LinphoneCall *call){ prevelem=elem; } elem=prevelem; - linphone_call_log_destroy((LinphoneCallLog*)elem->data); + linphone_call_log_unref((LinphoneCallLog*)elem->data); lc->call_logs=ms_list_remove_link(lc->call_logs,elem); } if (lc->vtable.call_log_updated!=NULL){ @@ -3186,7 +3184,7 @@ void linphone_call_zoom_video(LinphoneCall* call, float zoom_factor, float* cx, zoom[0] = zoom_factor; zoom[1] = *cx; zoom[2] = *cy; - ms_filter_call_method(vstream->output, MS_VIDEO_DISPLAY_ZOOM, &zoom); + ms_filter_call_method(vstream->output, MS_VIDEO_DISPLAY_ZOOM, &zoom); }else ms_warning("Could not apply zoom: video output wasn't activated."); } diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 1dc887bed..1827290c4 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -4497,7 +4497,7 @@ const MSList * linphone_core_get_call_logs(LinphoneCore *lc){ void linphone_core_clear_call_logs(LinphoneCore *lc){ lc->missed_calls=0; - ms_list_for_each(lc->call_logs,(void (*)(void*))linphone_call_log_destroy); + ms_list_for_each(lc->call_logs,(void (*)(void*))linphone_call_log_unref); lc->call_logs=ms_list_free(lc->call_logs); call_logs_write_to_config_file(lc); } @@ -4513,7 +4513,7 @@ void linphone_core_reset_missed_calls_count(LinphoneCore *lc) { void linphone_core_remove_call_log(LinphoneCore *lc, LinphoneCallLog *cl){ lc->call_logs = ms_list_remove(lc->call_logs, cl); call_logs_write_to_config_file(lc); - linphone_call_log_destroy(cl); + linphone_call_log_unref(cl); } @@ -5735,7 +5735,7 @@ static void linphone_core_uninit(LinphoneCore *lc) lp_config_destroy(lc->config); lc->config = NULL; /* Mark the config as NULL to block further calls */ - ms_list_for_each(lc->call_logs,(void (*)(void*))linphone_call_log_destroy); + ms_list_for_each(lc->call_logs,(void (*)(void*))linphone_call_log_unref); lc->call_logs=ms_list_free(lc->call_logs); ms_list_for_each(lc->last_recv_msg_ids,ms_free); diff --git a/coreapi/private.h b/coreapi/private.h index 78e990b61..cbcaa3421 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -238,15 +238,14 @@ struct _LinphoneCall bool_t all_muted; /*this flag is set during early medias*/ bool_t playing_ringbacktone; - bool_t owns_call_log; bool_t ringing_beep; /* whether this call is ringing through an already existent current call*/ - bool_t auth_token_verified; + bool_t defer_update; - bool_t was_automatically_paused; bool_t ping_replied; bool_t record_active; + bool_t paused_by_app; }; @@ -259,7 +258,7 @@ void linphone_call_set_state(LinphoneCall *call, LinphoneCallState cstate, const void linphone_call_set_contact_op(LinphoneCall* call); void linphone_call_set_compatible_incoming_call_parameters(LinphoneCall *call, const SalMediaDescription *md); /* private: */ -LinphoneCallLog * linphone_call_log_new(LinphoneCall *call, LinphoneAddress *local, LinphoneAddress * remote); +LinphoneCallLog * linphone_call_log_new(LinphoneCallDir dir, LinphoneAddress *local, LinphoneAddress * remote); void linphone_call_log_completed(LinphoneCall *call); void linphone_call_log_destroy(LinphoneCallLog *cl); void linphone_call_set_transfer_state(LinphoneCall* call, LinphoneCallState state);