Commit a3b3867a authored by Sylvain Berfini's avatar Sylvain Berfini 🎩
Browse files

More leaks fixed

parent ae313e70
...@@ -102,6 +102,9 @@ static int find_matching_friend(LinphoneFriend *lf1, LinphoneFriend *lf2) { ...@@ -102,6 +102,9 @@ static int find_matching_friend(LinphoneFriend *lf1, LinphoneFriend *lf2) {
} }
static void linphone_carddav_response_free(LinphoneCardDavResponse *response) { static void linphone_carddav_response_free(LinphoneCardDavResponse *response) {
if (response->etag) ms_free(response->etag);
if (response->url) ms_free(response->url);
if (response->vcard) ms_free(response->vcard);
ms_free(response); ms_free(response);
} }
...@@ -343,6 +346,13 @@ static void linphone_carddav_query_free(LinphoneCardDavQuery *query) { ...@@ -343,6 +346,13 @@ static void linphone_carddav_query_free(LinphoneCardDavQuery *query) {
// Context will be freed later (in sync_done) // Context will be freed later (in sync_done)
query->context = NULL; query->context = NULL;
if (query->url) {
ms_free(query->url);
}
if (query->body) {
ms_free(query->body);
}
ms_free(query); ms_free(query);
} }
...@@ -404,7 +414,7 @@ static void process_response_from_carddav_request(void *data, const belle_http_r ...@@ -404,7 +414,7 @@ static void process_response_from_carddav_request(void *data, const belle_http_r
// We need to do a GET on the vCard to get the correct one // We need to do a GET on the vCard to get the correct one
bctbx_list_t *vcard = NULL; bctbx_list_t *vcard = NULL;
LinphoneCardDavResponse *response = (LinphoneCardDavResponse *)ms_new0(LinphoneCardDavResponse, 1); LinphoneCardDavResponse *response = (LinphoneCardDavResponse *)ms_new0(LinphoneCardDavResponse, 1);
response->url = linphone_vcard_get_url(lvc); response->url = ms_strdup(linphone_vcard_get_url(lvc));
vcard = bctbx_list_append(vcard, response); vcard = bctbx_list_append(vcard, response);
linphone_carddav_pull_vcards(query->context, vcard); linphone_carddav_pull_vcards(query->context, vcard);
bctbx_list_free_with_data(vcard, (void (*)(void *))linphone_carddav_response_free); bctbx_list_free_with_data(vcard, (void (*)(void *))linphone_carddav_response_free);
...@@ -551,9 +561,9 @@ static LinphoneCardDavQuery* linphone_carddav_create_put_query(LinphoneCardDavCo ...@@ -551,9 +561,9 @@ static LinphoneCardDavQuery* linphone_carddav_create_put_query(LinphoneCardDavCo
query->context = cdc; query->context = cdc;
query->depth = NULL; query->depth = NULL;
query->ifmatch = linphone_vcard_get_etag(lvc); query->ifmatch = linphone_vcard_get_etag(lvc);
query->body = linphone_vcard_as_vcard4_string(lvc); query->body = ms_strdup(linphone_vcard_as_vcard4_string(lvc));
query->method = "PUT"; query->method = "PUT";
query->url = linphone_vcard_get_url(lvc); query->url = ms_strdup(linphone_vcard_get_url(lvc));
query->type = LinphoneCardDavQueryTypePut; query->type = LinphoneCardDavQueryTypePut;
return query; return query;
} }
...@@ -625,7 +635,7 @@ static LinphoneCardDavQuery* linphone_carddav_create_delete_query(LinphoneCardDa ...@@ -625,7 +635,7 @@ static LinphoneCardDavQuery* linphone_carddav_create_delete_query(LinphoneCardDa
query->ifmatch = linphone_vcard_get_etag(lvc); query->ifmatch = linphone_vcard_get_etag(lvc);
query->body = NULL; query->body = NULL;
query->method = "DELETE"; query->method = "DELETE";
query->url = linphone_vcard_get_url(lvc); query->url = ms_strdup(linphone_vcard_get_url(lvc));
query->type = LinphoneCardDavQueryTypeDelete; query->type = LinphoneCardDavQueryTypeDelete;
return query; return query;
} }
...@@ -693,9 +703,9 @@ static LinphoneCardDavQuery* linphone_carddav_create_propfind_query(LinphoneCard ...@@ -693,9 +703,9 @@ static LinphoneCardDavQuery* linphone_carddav_create_propfind_query(LinphoneCard
query->context = cdc; query->context = cdc;
query->depth = "0"; query->depth = "0";
query->ifmatch = NULL; query->ifmatch = NULL;
query->body = "<d:propfind xmlns:d=\"DAV:\" xmlns:cs=\"http://calendarserver.org/ns/\"><d:prop><cs:getctag /></d:prop></d:propfind>"; query->body = ms_strdup("<d:propfind xmlns:d=\"DAV:\" xmlns:cs=\"http://calendarserver.org/ns/\"><d:prop><cs:getctag /></d:prop></d:propfind>");
query->method = "PROPFIND"; query->method = "PROPFIND";
query->url = cdc->friend_list->uri; query->url = ms_strdup(cdc->friend_list->uri);
query->type = LinphoneCardDavQueryTypePropfind; query->type = LinphoneCardDavQueryTypePropfind;
return query; return query;
} }
...@@ -710,9 +720,9 @@ static LinphoneCardDavQuery* linphone_carddav_create_addressbook_query(LinphoneC ...@@ -710,9 +720,9 @@ static LinphoneCardDavQuery* linphone_carddav_create_addressbook_query(LinphoneC
query->context = cdc; query->context = cdc;
query->depth = "1"; query->depth = "1";
query->ifmatch = NULL; query->ifmatch = NULL;
query->body = "<card:addressbook-query xmlns:d=\"DAV:\" xmlns:card=\"urn:ietf:params:xml:ns:carddav\"><d:prop><d:getetag /></d:prop><card:filter></card:filter></card:addressbook-query>"; query->body = ms_strdup("<card:addressbook-query xmlns:d=\"DAV:\" xmlns:card=\"urn:ietf:params:xml:ns:carddav\"><d:prop><d:getetag /></d:prop><card:filter></card:filter></card:addressbook-query>");
query->method = "REPORT"; query->method = "REPORT";
query->url = cdc->friend_list->uri; query->url = ms_strdup(cdc->friend_list->uri);
query->type = LinphoneCardDavQueryTypeAddressbookQuery; query->type = LinphoneCardDavQueryTypeAddressbookQuery;
return query; return query;
} }
...@@ -731,7 +741,7 @@ static LinphoneCardDavQuery* linphone_carddav_create_addressbook_multiget_query( ...@@ -731,7 +741,7 @@ static LinphoneCardDavQuery* linphone_carddav_create_addressbook_multiget_query(
query->depth = "1"; query->depth = "1";
query->ifmatch = NULL; query->ifmatch = NULL;
query->method = "REPORT"; query->method = "REPORT";
query->url = cdc->friend_list->uri; query->url = ms_strdup(cdc->friend_list->uri);
query->type = LinphoneCardDavQueryTypeAddressbookMultiget; query->type = LinphoneCardDavQueryTypeAddressbookMultiget;
sprintf(body, "%s", "<card:addressbook-multiget xmlns:d=\"DAV:\" xmlns:card=\"urn:ietf:params:xml:ns:carddav\"><d:prop><d:getetag /><card:address-data content-type='text/vcard' version='4.0'/></d:prop>"); sprintf(body, "%s", "<card:addressbook-multiget xmlns:d=\"DAV:\" xmlns:card=\"urn:ietf:params:xml:ns:carddav\"><d:prop><d:getetag /><card:address-data content-type='text/vcard' version='4.0'/></d:prop>");
......
...@@ -220,7 +220,9 @@ int linphone_friend_set_address(LinphoneFriend *lf, const LinphoneAddress *addr) ...@@ -220,7 +220,9 @@ int linphone_friend_set_address(LinphoneFriend *lf, const LinphoneAddress *addr)
vcard = lf->vcard; vcard = lf->vcard;
if (vcard) { if (vcard) {
linphone_vcard_edit_main_sip_address(vcard, linphone_address_as_string_uri_only(fr)); char *address = linphone_address_as_string_uri_only(fr);
linphone_vcard_edit_main_sip_address(vcard, address);
ms_free(address);
} }
return 0; return 0;
...@@ -228,6 +230,8 @@ int linphone_friend_set_address(LinphoneFriend *lf, const LinphoneAddress *addr) ...@@ -228,6 +230,8 @@ int linphone_friend_set_address(LinphoneFriend *lf, const LinphoneAddress *addr)
void linphone_friend_add_address(LinphoneFriend *lf, const LinphoneAddress *addr) { void linphone_friend_add_address(LinphoneFriend *lf, const LinphoneAddress *addr) {
LinphoneVcard *vcard = NULL; LinphoneVcard *vcard = NULL;
char *address = NULL;
if (!lf || !addr) { if (!lf || !addr) {
return; return;
} }
...@@ -242,7 +246,9 @@ void linphone_friend_add_address(LinphoneFriend *lf, const LinphoneAddress *addr ...@@ -242,7 +246,9 @@ void linphone_friend_add_address(LinphoneFriend *lf, const LinphoneAddress *addr
return; return;
} }
linphone_vcard_add_sip_address(vcard, linphone_address_as_string_uri_only(addr)); address = linphone_address_as_string_uri_only(addr);
linphone_vcard_add_sip_address(vcard, address);
ms_free(address);
} }
bctbx_list_t* linphone_friend_get_addresses(LinphoneFriend *lf) { bctbx_list_t* linphone_friend_get_addresses(LinphoneFriend *lf) {
...@@ -276,6 +282,7 @@ bctbx_list_t* linphone_friend_get_addresses(LinphoneFriend *lf) { ...@@ -276,6 +282,7 @@ bctbx_list_t* linphone_friend_get_addresses(LinphoneFriend *lf) {
void linphone_friend_remove_address(LinphoneFriend *lf, const LinphoneAddress *addr) { void linphone_friend_remove_address(LinphoneFriend *lf, const LinphoneAddress *addr) {
LinphoneVcard *vcard = NULL; LinphoneVcard *vcard = NULL;
char * address = NULL;
if (!lf || !addr) { if (!lf || !addr) {
return; return;
} }
...@@ -284,8 +291,10 @@ void linphone_friend_remove_address(LinphoneFriend *lf, const LinphoneAddress *a ...@@ -284,8 +291,10 @@ void linphone_friend_remove_address(LinphoneFriend *lf, const LinphoneAddress *a
if (!vcard) { if (!vcard) {
return; return;
} }
linphone_vcard_remove_sip_address(vcard, linphone_address_as_string_uri_only(addr)); address = linphone_address_as_string_uri_only(addr);
linphone_vcard_remove_sip_address(vcard, address);
ms_free(address);
} }
void linphone_friend_add_phone_number(LinphoneFriend *lf, const char *phone) { void linphone_friend_add_phone_number(LinphoneFriend *lf, const char *phone) {
...@@ -444,6 +453,7 @@ static void _linphone_friend_destroy(LinphoneFriend *lf){ ...@@ -444,6 +453,7 @@ static void _linphone_friend_destroy(LinphoneFriend *lf){
if (lf->uri!=NULL) linphone_address_unref(lf->uri); if (lf->uri!=NULL) linphone_address_unref(lf->uri);
if (lf->info!=NULL) buddy_info_free(lf->info); if (lf->info!=NULL) buddy_info_free(lf->info);
if (lf->vcard != NULL) linphone_vcard_free(lf->vcard); if (lf->vcard != NULL) linphone_vcard_free(lf->vcard);
if (lf->refkey != NULL) ms_free(lf->refkey);
} }
static belle_sip_error_code _linphone_friend_marshall(belle_sip_object_t *obj, char* buff, size_t buff_size, size_t *offset) { static belle_sip_error_code _linphone_friend_marshall(belle_sip_object_t *obj, char* buff, size_t buff_size, size_t *offset) {
...@@ -1563,15 +1573,18 @@ void linphone_core_migrate_friends_from_rc_to_db(LinphoneCore *lc) { ...@@ -1563,15 +1573,18 @@ void linphone_core_migrate_friends_from_rc_to_db(LinphoneCore *lc) {
const LinphoneAddress *addr = linphone_friend_get_address(lf); const LinphoneAddress *addr = linphone_friend_get_address(lf);
if (addr) { if (addr) {
const char *displayName = linphone_address_get_display_name(addr); const char *displayName = linphone_address_get_display_name(addr);
char *address = NULL;
if (!displayName) { if (!displayName) {
displayName = linphone_address_get_username(addr); displayName = linphone_address_get_username(addr);
} }
address = linphone_address_as_string(addr);
if (!linphone_friend_create_vcard(lf, displayName)) { if (!linphone_friend_create_vcard(lf, displayName)) {
ms_warning("Couldn't create vCard for friend %s", linphone_address_as_string(addr)); ms_warning("Couldn't create vCard for friend %s", address);
} else { } else {
linphone_vcard_add_sip_address(linphone_friend_get_vcard(lf), linphone_address_as_string_uri_only(addr)); linphone_vcard_add_sip_address(linphone_friend_get_vcard(lf), address);
} }
ms_free(address);
linphone_friend_list_add_friend(lfl, lf); linphone_friend_list_add_friend(lfl, lf);
linphone_friend_unref(lf); linphone_friend_unref(lf);
......
...@@ -1308,9 +1308,9 @@ struct _LinphoneCardDavContext { ...@@ -1308,9 +1308,9 @@ struct _LinphoneCardDavContext {
struct _LinphoneCardDavQuery { struct _LinphoneCardDavQuery {
LinphoneCardDavContext *context; LinphoneCardDavContext *context;
const char *url; char *url;
const char *method; const char *method;
const char *body; char *body;
const char *depth; const char *depth;
const char *ifmatch; const char *ifmatch;
belle_http_request_listener_t *http_request_listener; belle_http_request_listener_t *http_request_listener;
...@@ -1319,9 +1319,9 @@ struct _LinphoneCardDavQuery { ...@@ -1319,9 +1319,9 @@ struct _LinphoneCardDavQuery {
}; };
struct _LinphoneCardDavResponse { struct _LinphoneCardDavResponse {
const char *etag; char *etag;
const char *url; char *url;
const char *vcard; char *vcard;
}; };
/***************************************************************************** /*****************************************************************************
......
...@@ -48,7 +48,8 @@ static LinphoneVcard* linphone_vcard_new_from_belcard(shared_ptr<belcard::BelCar ...@@ -48,7 +48,8 @@ static LinphoneVcard* linphone_vcard_new_from_belcard(shared_ptr<belcard::BelCar
void linphone_vcard_free(LinphoneVcard *vCard) { void linphone_vcard_free(LinphoneVcard *vCard) {
if (!vCard) return; if (!vCard) return;
if (vCard->etag) ms_free(vCard->etag);
if (vCard->url) ms_free(vCard->url);
vCard->belCard.reset(); vCard->belCard.reset();
ms_free(vCard); ms_free(vCard);
} }
...@@ -240,7 +241,7 @@ bool_t linphone_vcard_generate_unique_id(LinphoneVcard *vCard) { ...@@ -240,7 +241,7 @@ bool_t linphone_vcard_generate_unique_id(LinphoneVcard *vCard) {
if (sal_generate_uuid(uuid, sizeof(uuid)) == 0) { if (sal_generate_uuid(uuid, sizeof(uuid)) == 0) {
char vcard_uuid[sizeof(uuid)+4]; char vcard_uuid[sizeof(uuid)+4];
snprintf(vcard_uuid, sizeof(vcard_uuid), "urn:%s", uuid); snprintf(vcard_uuid, sizeof(vcard_uuid), "urn:%s", uuid);
linphone_vcard_set_uid(vCard, ms_strdup(vcard_uuid)); linphone_vcard_set_uid(vCard, vcard_uuid);
return TRUE; return TRUE;
} }
} }
......
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