Commit 509b105b authored by johan's avatar johan

File transfer: fix memory leak

parent c10b5f65
......@@ -153,6 +153,8 @@ static void linphone_chat_message_process_response_from_post_file(void *data, co
if (code == 200 ) { /* file has been uplaoded correctly, get server reply and send it */
const char *body = belle_sip_message_get_body((belle_sip_message_t *)event->response);
msg->message = ms_strdup(body);
linphone_content_uninit(msg->file_transfer_information);
ms_free(msg->file_transfer_information);
msg->file_transfer_information = NULL;
msg->content_type = ms_strdup("application/vnd.gsma.rcs-ft-http+xml");
_linphone_chat_room_send_message(msg->chat_room, msg);
......@@ -644,6 +646,7 @@ LinphoneChatMessage* linphone_chat_room_create_message(LinphoneChatRoom *cr, con
msg->message=message?ms_strdup(message):NULL;
msg->is_read=TRUE;
msg->content_type = NULL; /* this property is used only when transfering file */
msg->file_transfer_information = NULL; /* this property is used only when transfering file */
return msg;
}
......@@ -671,6 +674,7 @@ LinphoneChatMessage* linphone_chat_room_create_message_2(
msg->state=state;
msg->is_read=is_read;
msg->content_type = NULL; /* this property is used only when transfering file */
msg->file_transfer_information = NULL; /* this property is used only when transfering file */
if (is_incoming) {
msg->dir=LinphoneChatMessageIncoming;
linphone_chat_message_set_from(msg, linphone_chat_room_get_peer_address(cr));
......@@ -1135,6 +1139,10 @@ static void _linphone_chat_message_destroy(LinphoneChatMessage* msg) {
if (msg->to) linphone_address_destroy(msg->to);
if (msg->custom_headers) sal_custom_header_free(msg->custom_headers);
if (msg->content_type) ms_free(msg->content_type);
if (msg->file_transfer_information) {
linphone_content_uninit(msg->file_transfer_information);
ms_free(msg->file_transfer_information);
}
}
......@@ -1182,7 +1190,9 @@ LinphoneChatMessage* linphone_chat_room_create_file_transfer_message(LinphoneCha
LinphoneChatMessage* msg = belle_sip_object_new(LinphoneChatMessage);
msg->chat_room=(LinphoneChatRoom*)cr;
msg->message = NULL;
msg->file_transfer_information = initial_content;
msg->file_transfer_information = (LinphoneContent *)malloc(sizeof(LinphoneContent));
memset(msg->file_transfer_information, 0, sizeof(LinphoneContent));
linphone_content_copy(msg->file_transfer_information, initial_content);
msg->dir=LinphoneChatMessageOutgoing;
linphone_chat_message_set_to(msg, linphone_chat_room_get_peer_address(cr));
linphone_chat_message_set_from(msg, linphone_address_new(linphone_core_get_identity(cr->lc)));
......
......@@ -82,6 +82,8 @@ static void file_transfer_received(LinphoneCore *lc, LinphoneChatMessage *messag
if (size==0) {
printf("File transfert completed\n");
linphone_chat_room_destroy(linphone_chat_message_get_chat_room(message));
linphone_chat_message_destroy(message);
close(file);
running=FALSE;
} else { /* store content on a file*/
......@@ -220,6 +222,7 @@ int main(int argc, char *argv[]){
ms_usleep(50000);
}
printf("Shutting down...\n");
linphone_chat_room_destroy(chat_room);
linphone_core_destroy(lc);
......
......@@ -42,10 +42,11 @@ struct _LinphoneInfoMessage{
ptr->field=ms_strdup(val); \
}
static void linphone_content_copy(LinphoneContent *obj, const LinphoneContent *ref){
void linphone_content_copy(LinphoneContent *obj, const LinphoneContent *ref){
SET_STRING(obj,type,ref->type);
SET_STRING(obj,subtype,ref->subtype);
SET_STRING(obj,encoding,ref->encoding);
SET_STRING(obj,name,ref->name);
if (obj->data) {
ms_free(obj->data);
obj->data=NULL;
......@@ -63,6 +64,7 @@ void linphone_content_uninit(LinphoneContent * obj){
if (obj->subtype) ms_free(obj->subtype);
if (obj->data) ms_free(obj->data);
if (obj->encoding) ms_free(obj->encoding);
if (obj->name) ms_free(obj->name);
}
LinphoneContent *linphone_content_copy_from_sal_body(LinphoneContent *obj, const SalBody *ref){
......
......@@ -818,6 +818,7 @@ void linphone_call_create_op(LinphoneCall *call);
int linphone_call_prepare_ice(LinphoneCall *call, bool_t incoming_offer);
void linphone_core_notify_info_message(LinphoneCore* lc,SalOp *op, const SalBody *body);
void linphone_content_uninit(LinphoneContent * obj);
void linphone_content_copy(LinphoneContent *obj, const LinphoneContent *ref);
LinphoneContent *linphone_content_copy_from_sal_body(LinphoneContent *obj, const SalBody *ref);
SalBody *sal_body_from_content(SalBody *body, const LinphoneContent *lc);
SalReason linphone_reason_to_sal(LinphoneReason reason);
......
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