Commit dd369390 authored by Ghislain MARY's avatar Ghislain MARY
Browse files

Fix some memory leaks.

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