diff --git a/coreapi/carddav.c b/coreapi/carddav.c index c61ef8905..e6aef80be 100644 --- a/coreapi/carddav.c +++ b/coreapi/carddav.c @@ -102,6 +102,9 @@ static int find_matching_friend(LinphoneFriend *lf1, LinphoneFriend *lf2) { } 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); } @@ -343,6 +346,13 @@ static void linphone_carddav_query_free(LinphoneCardDavQuery *query) { // Context will be freed later (in sync_done) query->context = NULL; + if (query->url) { + ms_free(query->url); + } + if (query->body) { + ms_free(query->body); + } + ms_free(query); } @@ -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 bctbx_list_t *vcard = NULL; 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); linphone_carddav_pull_vcards(query->context, vcard); bctbx_list_free_with_data(vcard, (void (*)(void *))linphone_carddav_response_free); @@ -551,9 +561,9 @@ static LinphoneCardDavQuery* linphone_carddav_create_put_query(LinphoneCardDavCo query->context = cdc; query->depth = NULL; 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->url = linphone_vcard_get_url(lvc); + query->url = ms_strdup(linphone_vcard_get_url(lvc)); query->type = LinphoneCardDavQueryTypePut; return query; } @@ -625,7 +635,7 @@ static LinphoneCardDavQuery* linphone_carddav_create_delete_query(LinphoneCardDa query->ifmatch = linphone_vcard_get_etag(lvc); query->body = NULL; query->method = "DELETE"; - query->url = linphone_vcard_get_url(lvc); + query->url = ms_strdup(linphone_vcard_get_url(lvc)); query->type = LinphoneCardDavQueryTypeDelete; return query; } @@ -693,9 +703,9 @@ static LinphoneCardDavQuery* linphone_carddav_create_propfind_query(LinphoneCard query->context = cdc; query->depth = "0"; query->ifmatch = NULL; - query->body = ""; + query->body = ms_strdup(""); query->method = "PROPFIND"; - query->url = cdc->friend_list->uri; + query->url = ms_strdup(cdc->friend_list->uri); query->type = LinphoneCardDavQueryTypePropfind; return query; } @@ -710,9 +720,9 @@ static LinphoneCardDavQuery* linphone_carddav_create_addressbook_query(LinphoneC query->context = cdc; query->depth = "1"; query->ifmatch = NULL; - query->body = ""; + query->body = ms_strdup(""); query->method = "REPORT"; - query->url = cdc->friend_list->uri; + query->url = ms_strdup(cdc->friend_list->uri); query->type = LinphoneCardDavQueryTypeAddressbookQuery; return query; } @@ -731,7 +741,7 @@ static LinphoneCardDavQuery* linphone_carddav_create_addressbook_multiget_query( query->depth = "1"; query->ifmatch = NULL; query->method = "REPORT"; - query->url = cdc->friend_list->uri; + query->url = ms_strdup(cdc->friend_list->uri); query->type = LinphoneCardDavQueryTypeAddressbookMultiget; sprintf(body, "%s", ""); diff --git a/coreapi/friend.c b/coreapi/friend.c index 1a105dd54..415bbc1ee 100644 --- a/coreapi/friend.c +++ b/coreapi/friend.c @@ -220,7 +220,9 @@ int linphone_friend_set_address(LinphoneFriend *lf, const LinphoneAddress *addr) vcard = lf->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; @@ -228,6 +230,8 @@ int linphone_friend_set_address(LinphoneFriend *lf, const LinphoneAddress *addr) void linphone_friend_add_address(LinphoneFriend *lf, const LinphoneAddress *addr) { LinphoneVcard *vcard = NULL; + char *address = NULL; + if (!lf || !addr) { return; } @@ -242,7 +246,9 @@ void linphone_friend_add_address(LinphoneFriend *lf, const LinphoneAddress *addr 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) { @@ -276,6 +282,7 @@ bctbx_list_t* linphone_friend_get_addresses(LinphoneFriend *lf) { void linphone_friend_remove_address(LinphoneFriend *lf, const LinphoneAddress *addr) { LinphoneVcard *vcard = NULL; + char * address = NULL; if (!lf || !addr) { return; } @@ -284,8 +291,10 @@ void linphone_friend_remove_address(LinphoneFriend *lf, const LinphoneAddress *a if (!vcard) { 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) { @@ -444,6 +453,7 @@ static void _linphone_friend_destroy(LinphoneFriend *lf){ if (lf->uri!=NULL) linphone_address_unref(lf->uri); if (lf->info!=NULL) buddy_info_free(lf->info); 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) { @@ -1563,15 +1573,18 @@ void linphone_core_migrate_friends_from_rc_to_db(LinphoneCore *lc) { const LinphoneAddress *addr = linphone_friend_get_address(lf); if (addr) { const char *displayName = linphone_address_get_display_name(addr); + char *address = NULL; if (!displayName) { displayName = linphone_address_get_username(addr); } + address = linphone_address_as_string(addr); 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 { - 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_unref(lf); diff --git a/coreapi/private.h b/coreapi/private.h index 21b546955..e0ca97b0a 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -1308,9 +1308,9 @@ struct _LinphoneCardDavContext { struct _LinphoneCardDavQuery { LinphoneCardDavContext *context; - const char *url; + char *url; const char *method; - const char *body; + char *body; const char *depth; const char *ifmatch; belle_http_request_listener_t *http_request_listener; @@ -1319,9 +1319,9 @@ struct _LinphoneCardDavQuery { }; struct _LinphoneCardDavResponse { - const char *etag; - const char *url; - const char *vcard; + char *etag; + char *url; + char *vcard; }; /***************************************************************************** diff --git a/coreapi/vcard.cc b/coreapi/vcard.cc index 95b13dcd9..b4b566d89 100644 --- a/coreapi/vcard.cc +++ b/coreapi/vcard.cc @@ -48,7 +48,8 @@ static LinphoneVcard* linphone_vcard_new_from_belcard(shared_ptretag) ms_free(vCard->etag); + if (vCard->url) ms_free(vCard->url); vCard->belCard.reset(); ms_free(vCard); } @@ -240,7 +241,7 @@ bool_t linphone_vcard_generate_unique_id(LinphoneVcard *vCard) { if (sal_generate_uuid(uuid, sizeof(uuid)) == 0) { char vcard_uuid[sizeof(uuid)+4]; 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; } }