Commit dd369390 authored by Ghislain MARY's avatar Ghislain MARY

Fix some memory leaks.

parent fb04d714
......@@ -160,8 +160,7 @@ void __linphone_friend_do_subscribe(LinphoneFriend *fr){
if (fr->outsub==NULL){
/* people for which we don't have yet an answer should appear as offline */
bctbx_list_free_with_data(fr->presence_models, (bctbx_list_free_func)free_friend_presence);
fr->presence_models = NULL;
fr->presence_models = bctbx_list_free_with_data(fr->presence_models, (bctbx_list_free_func)free_friend_presence);
/*
if (fr->lc->vtable.notify_recv)
fr->lc->vtable.notify_recv(fr->lc,(LinphoneFriend*)fr);
......@@ -265,7 +264,10 @@ LinphoneAddress * linphone_friend_get_address(const LinphoneFriend *lf) {
bctbx_list_t *sip_addresses = linphone_vcard_get_sip_addresses(lf->vcard);
if (sip_addresses) {
const char *uri = (const char *)bctbx_list_nth_data(sip_addresses, 0);
if (uri) return linphone_address_new(uri);
LinphoneAddress *addr = NULL;
if (uri) addr = linphone_address_new(uri);
bctbx_list_free(sip_addresses);
return addr;
}
}
return NULL;
......@@ -1221,7 +1223,6 @@ void linphone_core_friends_storage_init(LinphoneCore *lc) {
if (friends_lists) {
ms_warning("Replacing current default friend list by the one(s) from the database");
lc->friends_lists = bctbx_list_free_with_data(lc->friends_lists, (void (*)(void*))linphone_friend_list_unref);
lc->friends_lists = NULL;
while (friends_lists) {
LinphoneFriendList *list = (LinphoneFriendList *)bctbx_list_get_data(friends_lists);
......@@ -1691,5 +1692,5 @@ const char * linphone_friend_sip_uri_to_phone_number(LinphoneFriend *lf, const c
}
void linphone_friend_clear_presence_models(LinphoneFriend *lf) {
bctbx_list_free_with_data(lf->presence_models, (bctbx_list_free_func)free_friend_presence);
lf->presence_models = bctbx_list_free_with_data(lf->presence_models, (bctbx_list_free_func)free_friend_presence);
}
\ No newline at end of file
......@@ -301,6 +301,7 @@ static void linphone_friend_list_parse_multipart_related_body(LinphoneFriendList
ms_free(uri);
iterator = bctbx_list_next(iterator);
}
if (addresses) bctbx_list_free_with_data(addresses, (bctbx_list_free_func)linphone_address_unref);
iterator = numbers;
while (iterator) {
const char *number = (const char *)bctbx_list_get_data(iterator);
......@@ -308,6 +309,7 @@ static void linphone_friend_list_parse_multipart_related_body(LinphoneFriendList
linphone_core_notify_notify_presence_received_for_uri_or_tel(list->lc, lf, number, presence);
iterator = bctbx_list_next(iterator);
}
if (numbers) bctbx_list_free(numbers);
if (linphone_friend_is_presence_received(lf) == TRUE) {
linphone_core_notify_notify_presence_received(list->lc, lf);
}
......@@ -456,17 +458,14 @@ static LinphoneFriendListStatus _linphone_friend_list_add_friend(LinphoneFriendL
}
if (bctbx_list_find(list->friends, lf) != NULL) {
char *tmp = NULL;
LinphoneAddress *addr = linphone_friend_get_address(lf);
if (addr) tmp = linphone_address_as_string(addr);
ms_warning("Friend %s already in list [%s], ignored.", tmp ? tmp : "unknown", list->display_name);
if (tmp) {
ms_free(tmp);
linphone_address_unref(addr);
}
if (tmp) ms_free(tmp);
} else {
status = linphone_friend_list_import_friend(list, lf, synchronize);
linphone_friend_save(lf, lf->lc);
}
if (addr) linphone_address_unref(addr);
if (list->rls_uri == NULL) {
/* Mimic the behaviour of linphone_core_add_friend() when a resource list server is not in use */
linphone_friend_apply(lf, lf->lc);
......@@ -492,6 +491,7 @@ LinphoneFriendListStatus linphone_friend_list_import_friend(LinphoneFriendList *
if (addr) linphone_address_unref(addr);
return LinphoneFriendListInvalidFriend;
}
linphone_address_unref(addr);
lf->friend_list = list;
lf->lc = list->lc;
list->friends = bctbx_list_append(list->friends, linphone_friend_ref(lf));
......@@ -655,6 +655,7 @@ LinphoneFriend * linphone_friend_list_find_friend_by_address(const LinphoneFrien
if (linphone_address_weak_equal(lfaddr, address)) result = lf;
iterator = bctbx_list_next(iterator);
}
bctbx_list_free_with_data(addresses, (bctbx_list_free_func)linphone_address_unref);
}
}
return result;
......
......@@ -23,6 +23,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "sal/sal.h"
#include <bctoolbox/crypto.h>
#define VCARD_MD5_HASH_SIZE 16
struct _LinphoneVcardContext {
belcard::BelCardParser *parser;
void *user_data;
......@@ -32,7 +35,7 @@ struct _LinphoneVcard {
shared_ptr<belcard::BelCard> belCard;
char *etag;
char *url;
unsigned char *md5;
unsigned char md5[VCARD_MD5_HASH_SIZE];
};
#ifdef __cplusplus
......@@ -368,36 +371,18 @@ const char* linphone_vcard_get_url(const LinphoneVcard *vCard) {
return vCard->url;
}
#define VCARD_MD5_HASH_SIZE 16
void linphone_vcard_compute_md5_hash(LinphoneVcard *vCard) {
unsigned char digest[VCARD_MD5_HASH_SIZE];
const char *text = NULL;
if (!vCard) {
return;
}
if (!vCard) return;
text = linphone_vcard_as_vcard4_string(vCard);
bctbx_md5((unsigned char *)text, strlen(text), digest);
vCard->md5 = (unsigned char *)ms_malloc(sizeof(digest));
memcpy(vCard->md5, digest, sizeof(digest));
bctbx_md5((unsigned char *)text, strlen(text), vCard->md5);
}
bool_t linphone_vcard_compare_md5_hash(LinphoneVcard *vCard) {
unsigned char *previous_md5 = vCard->md5;
unsigned char *new_md5 = NULL;
int result = -1;
if (!previous_md5) {
return result;
}
unsigned char previous_md5[VCARD_MD5_HASH_SIZE];
memcpy(previous_md5, vCard->md5, VCARD_MD5_HASH_SIZE);
linphone_vcard_compute_md5_hash(vCard);
new_md5 = vCard->md5;
result = memcmp(new_md5, previous_md5, VCARD_MD5_HASH_SIZE);
ms_free(previous_md5);
ms_free(new_md5);
return result;
return memcmp(vCard->md5, previous_md5, VCARD_MD5_HASH_SIZE);
}
bool_t linphone_core_vcard_supported(void) {
......
......@@ -649,6 +649,7 @@ static void presence_list_subscribe_io_error(void) {
static void long_term_presence_base(const char* addr, bool_t exist, const char* contact) {
LinphoneFriend* friend2;
char *presence_contact;
LinphoneCoreManager *pauline = linphone_core_manager_new(transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
linphone_core_set_user_agent(pauline->lc, "full-presence-support", NULL);
......@@ -663,12 +664,16 @@ static void long_term_presence_base(const char* addr, bool_t exist, const char*
BC_ASSERT_TRUE(wait_for(pauline->lc,NULL,&pauline->stat.number_of_LinphonePresenceActivityOnline,1));
BC_ASSERT_EQUAL(pauline->stat.number_of_LinphonePresenceActivityOnline, 1, int, "%d");
BC_ASSERT_EQUAL(linphone_presence_model_get_basic_status(linphone_friend_get_presence_model(friend2)), LinphonePresenceBasicStatusOpen, int, "%d");
BC_ASSERT_STRING_EQUAL(linphone_presence_model_get_contact(linphone_friend_get_presence_model(friend2)), contact);
presence_contact = linphone_presence_model_get_contact(linphone_friend_get_presence_model(friend2));
BC_ASSERT_STRING_EQUAL(presence_contact, contact);
if (presence_contact) ms_free(presence_contact);
} else {
BC_ASSERT_TRUE(wait_for(pauline->lc,NULL,&pauline->stat.number_of_LinphonePresenceActivityOffline,1));
BC_ASSERT_EQUAL(pauline->stat.number_of_LinphonePresenceActivityOffline, 1, int, "%d");
BC_ASSERT_EQUAL(linphone_presence_model_get_basic_status(linphone_friend_get_presence_model(friend2)), LinphonePresenceBasicStatusClosed, int, "%d");
BC_ASSERT_PTR_NULL(linphone_presence_model_get_contact(linphone_friend_get_presence_model(friend2)));
presence_contact = linphone_presence_model_get_contact(linphone_friend_get_presence_model(friend2));
BC_ASSERT_PTR_NULL(presence_contact);
if (presence_contact) ms_free(presence_contact);
}
linphone_friend_unref(friend2);
......
......@@ -252,6 +252,7 @@ static void subscribe_failure_handle_by_app(void) {
sal_set_recv_error(marie->lc->sal, 1);
lf = linphone_core_get_friend_by_address(marie->lc,lf_identity);
ms_free(lf_identity);
BC_ASSERT_PTR_NOT_NULL(lf);
linphone_friend_edit(lf);
linphone_friend_enable_subscribes(lf,FALSE); /*disable subscription*/
......
......@@ -120,7 +120,11 @@ static void linphone_vcard_update_existing_friends_test(void) {
LinphoneFriend *lf = linphone_friend_new_with_addr("sip:oldfriend@sip.linphone.org");
BC_ASSERT_PTR_NOT_NULL(lf);
BC_ASSERT_PTR_NULL(linphone_friend_get_vcard(lf));
if (linphone_core_vcard_supported()) {
BC_ASSERT_PTR_NOT_NULL(linphone_friend_get_vcard(lf));
} else {
BC_ASSERT_PTR_NULL(linphone_friend_get_vcard(lf));
}
linphone_friend_edit(lf);
linphone_friend_set_name(lf, "Old Friend");
......
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