From 86705803e42cf0039c0647ee33a7d0de19757de5 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Wed, 1 Jun 2016 13:58:53 +0200 Subject: [PATCH] Fix memory leaks. --- coreapi/linphonecall.c | 4 +++- coreapi/linphonecore.c | 8 +++++--- coreapi/misc.c | 2 +- coreapi/nat_policy.c | 1 + coreapi/presence.c | 1 + coreapi/proxy.c | 11 ++++++----- tester/call_tester.c | 6 +++--- tester/stun_tester.c | 2 ++ tester/tester.c | 1 + 9 files changed, 23 insertions(+), 13 deletions(-) diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index 36f1a6f5a..c3c8d6336 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -2475,13 +2475,15 @@ void linphone_call_init_audio_stream(LinphoneCall *call){ /* init zrtp even if we didn't explicitely set it, just in case peer offers it */ if (ms_zrtp_available()) { + char *uri = linphone_address_as_string_uri_only((call->dir==LinphoneCallIncoming) ? call->log->from : call->log->to); MSZrtpParams params; memset(¶ms,0,sizeof(MSZrtpParams)); /*call->current_params.media_encryption will be set later when zrtp is activated*/ params.zid_file=lc->zrtp_secrets_cache; - params.uri= linphone_address_as_string_uri_only((call->dir==LinphoneCallIncoming) ? call->log->from : call->log->to); + params.uri=uri; setZrtpCryptoTypesParameters(¶ms,call->core); audio_stream_enable_zrtp(call->audiostream,¶ms); + if (uri != NULL) ms_free(uri); } media_stream_reclaim_sessions(&audiostream->ms, &call->sessions[call->main_audio_stream_index]); diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index f78a5d5cd..d766d9855 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -5159,9 +5159,9 @@ void linphone_core_set_firewall_policy(LinphoneCore *lc, LinphoneFirewallPolicy char *stun_server_username = NULL; if (lc->nat_policy != NULL) { - nat_policy = linphone_nat_policy_ref(lc->nat_policy); - stun_server = ms_strdup(linphone_nat_policy_get_stun_server(lc->nat_policy)); - stun_server_username = ms_strdup(linphone_nat_policy_get_stun_server_username(lc->nat_policy)); + nat_policy = lc->nat_policy; + stun_server = ms_strdup(linphone_nat_policy_get_stun_server(nat_policy)); + stun_server_username = ms_strdup(linphone_nat_policy_get_stun_server_username(nat_policy)); linphone_nat_policy_clear(nat_policy); } else { nat_policy = linphone_core_create_nat_policy(lc); @@ -6374,6 +6374,8 @@ void net_config_uninit(LinphoneCore *lc) if (lc->nat_policy != NULL) { lp_config_set_string(lc->config, "net", "nat_policy_ref", lc->nat_policy->ref); linphone_nat_policy_save_to_config(lc->nat_policy); + linphone_nat_policy_unref(lc->nat_policy); + lc->nat_policy = NULL; } } diff --git a/coreapi/misc.c b/coreapi/misc.c index 4fb1f5a94..6c989b066 100644 --- a/coreapi/misc.c +++ b/coreapi/misc.c @@ -641,7 +641,7 @@ static void stun_auth_requested_cb(LinphoneCall *call, const char *realm, const const LinphoneAddress *addr = NULL; const LinphoneAuthInfo *auth_info = NULL; LinphoneCore *lc = call->core; - const char *user; + const char *user = NULL; // Get the username from the nat policy or the proxy config if (call->dest_proxy != NULL) proxy = call->dest_proxy; diff --git a/coreapi/nat_policy.c b/coreapi/nat_policy.c index 2e7e01b66..5df7e3c24 100644 --- a/coreapi/nat_policy.c +++ b/coreapi/nat_policy.c @@ -77,6 +77,7 @@ static void _linphone_nat_policy_save_to_config(const LinphoneNatPolicy *policy, } lp_config_set_string_list(config, section, "protocols", l); belle_sip_free(section); + ms_list_free(l); } void linphone_nat_policy_save_to_config(const LinphoneNatPolicy *policy) { diff --git a/coreapi/presence.c b/coreapi/presence.c index 22887cfd1..744cc7605 100644 --- a/coreapi/presence.c +++ b/coreapi/presence.c @@ -446,6 +446,7 @@ int linphone_presence_model_add_activity(LinphonePresenceModel *model, LinphoneP return -1; presence_model_add_person(model, person); + linphone_presence_person_unref(person); } else { /* Add the activity to the first person in the model. */ person = (LinphonePresencePerson *)ms_list_nth_data(model->persons, 0); diff --git a/coreapi/proxy.c b/coreapi/proxy.c index 9d63f5125..1a8f964c4 100644 --- a/coreapi/proxy.c +++ b/coreapi/proxy.c @@ -221,6 +221,9 @@ void _linphone_proxy_config_destroy(LinphoneProxyConfig *cfg){ if (cfg->sent_headers!=NULL) sal_custom_header_free(cfg->sent_headers); if (cfg->pending_contact) linphone_address_unref(cfg->pending_contact); if (cfg->refkey) ms_free(cfg->refkey); + if (cfg->nat_policy != NULL) { + linphone_nat_policy_unref(cfg->nat_policy); + } _linphone_proxy_config_release_ops(cfg); } @@ -1694,9 +1697,7 @@ LinphoneNatPolicy * linphone_proxy_config_get_nat_policy(const LinphoneProxyConf } void linphone_proxy_config_set_nat_policy(LinphoneProxyConfig *cfg, LinphoneNatPolicy *policy) { - if (cfg->nat_policy != NULL) { - linphone_nat_policy_unref(cfg->nat_policy); - cfg->nat_policy = NULL; - } - if (policy != NULL) cfg->nat_policy = linphone_nat_policy_ref(policy); + if (policy != NULL) policy = linphone_nat_policy_ref(policy); /* Prevent object destruction if the same policy is used */ + if (cfg->nat_policy != NULL) linphone_nat_policy_unref(cfg->nat_policy); + if (policy != NULL) cfg->nat_policy = policy; } diff --git a/tester/call_tester.c b/tester/call_tester.c index f35a1a4cf..2cdfc4686 100644 --- a/tester/call_tester.c +++ b/tester/call_tester.c @@ -3997,10 +3997,10 @@ void check_media_direction(LinphoneCoreManager* mgr, LinphoneCall *call, MSList* if (video_dir != LinphoneMediaDirectionInactive){ BC_ASSERT_TRUE(linphone_call_params_video_enabled(params)); + BC_ASSERT_EQUAL(linphone_call_params_get_video_direction(params), video_dir, int, "%d"); + linphone_call_set_next_video_frame_decoded_callback(call,linphone_call_iframe_decoded_cb,mgr->lc); + linphone_call_send_vfu_request(call); } - BC_ASSERT_EQUAL(linphone_call_params_get_video_direction(params), video_dir, int, "%d"); - linphone_call_set_next_video_frame_decoded_callback(call,linphone_call_iframe_decoded_cb,mgr->lc); - linphone_call_send_vfu_request(call); switch (video_dir) { case LinphoneMediaDirectionInactive: diff --git a/tester/stun_tester.c b/tester/stun_tester.c index 885054ff1..41df639cb 100644 --- a/tester/stun_tester.c +++ b/tester/stun_tester.c @@ -104,6 +104,8 @@ static void configure_nat_policy(LinphoneCore *lc, bool_t turn_enabled) { } linphone_core_set_nat_policy(lc, nat_policy); linphone_core_add_auth_info(lc, auth_info); + linphone_nat_policy_unref(nat_policy); + linphone_auth_info_destroy(auth_info); } static void ice_turn_call_base(bool_t forced_relay, bool_t caller_turn_enabled, bool_t callee_turn_enabled) { diff --git a/tester/tester.c b/tester/tester.c index cd32a1189..c932f68ce 100644 --- a/tester/tester.c +++ b/tester/tester.c @@ -556,6 +556,7 @@ int liblinphone_tester_after_each(void) { ms_error("%s", format); all_leaks_buffer = ms_strcat_printf(all_leaks_buffer, "\n%s", format); + ms_free(format); } // prevent any future leaks