diff --git a/coreapi/chat.c b/coreapi/chat.c index b7ecd439b..2d0a9dc18 100644 --- a/coreapi/chat.c +++ b/coreapi/chat.c @@ -117,13 +117,14 @@ void linphone_chat_message_cbs_set_file_transfer_progress_indication( BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneChatMessage); static void _linphone_chat_room_destroy(LinphoneChatRoom *cr) { - bctbx_list_free_with_data(cr->transient_messages, (void (*)(void *))linphone_chat_message_release); - if (cr->received_rtt_characters) { - cr->received_rtt_characters = bctbx_list_free_with_data(cr->received_rtt_characters, (void (*)(void *))ms_free); - } linphone_chat_room_delete_composing_idle_timer(cr); linphone_chat_room_delete_composing_refresh_timer(cr); linphone_chat_room_delete_remote_composing_refresh_timer(cr); + bctbx_list_free_with_data(cr->transient_messages, (bctbx_list_free_func)linphone_chat_message_release); + if (cr->weak_messages != NULL) bctbx_list_free(cr->weak_messages); + if (cr->received_rtt_characters) { + cr->received_rtt_characters = bctbx_list_free_with_data(cr->received_rtt_characters, (bctbx_list_free_func)ms_free); + } if (cr->lc != NULL) { if (bctbx_list_find(cr->lc->chatrooms, cr)) { ms_error("LinphoneChatRoom[%p] is destroyed while still being used by the LinphoneCore. This is abnormal." @@ -138,7 +139,6 @@ static void _linphone_chat_room_destroy(LinphoneChatRoom *cr) { if (cr->pending_message) linphone_chat_message_destroy(cr->pending_message); ms_free(cr->peer); - if (cr->weak_messages != NULL) bctbx_list_free(cr->weak_messages); } void linphone_chat_message_set_state(LinphoneChatMessage *msg, LinphoneChatMessageState state) { @@ -313,6 +313,7 @@ void linphone_chat_room_release(LinphoneChatRoom *cr) { linphone_chat_room_delete_composing_refresh_timer(cr); linphone_chat_room_delete_remote_composing_refresh_timer(cr); bctbx_list_for_each(cr->weak_messages, (bctbx_list_iterate_func)linphone_chat_message_deactivate); + bctbx_list_for_each(cr->transient_messages, (bctbx_list_iterate_func)linphone_chat_message_deactivate); cr->lc = NULL; linphone_chat_room_unref(cr); } @@ -1717,11 +1718,11 @@ void linphone_chat_message_unref(LinphoneChatMessage *msg) { } static void linphone_chat_message_deactivate(LinphoneChatMessage *msg){ + if (msg->file_transfer_information != NULL) { + _linphone_chat_message_cancel_file_transfer(msg, FALSE); + } /*mark the chat msg as orphan (it has no chat room anymore)*/ msg->chat_room = NULL; - if (msg->file_transfer_information != NULL) { - linphone_chat_message_cancel_file_transfer(msg); - } } static void linphone_chat_message_release(LinphoneChatMessage *msg) { diff --git a/coreapi/chat_file_transfer.c b/coreapi/chat_file_transfer.c index 3d5e69378..c1fd37984 100644 --- a/coreapi/chat_file_transfer.c +++ b/coreapi/chat_file_transfer.c @@ -613,7 +613,7 @@ void linphone_chat_message_start_file_download(LinphoneChatMessage *msg, linphone_chat_message_download_file(msg); } -void linphone_chat_message_cancel_file_transfer(LinphoneChatMessage *msg) { +void _linphone_chat_message_cancel_file_transfer(LinphoneChatMessage *msg, bool_t unref) { if (msg->http_request) { if (msg->state == LinphoneChatMessageStateInProgress) { linphone_chat_message_set_state(msg, LinphoneChatMessageStateNotDelivered); @@ -625,7 +625,7 @@ void linphone_chat_message_cancel_file_transfer(LinphoneChatMessage *msg) { , msg , msg->chat_room); belle_http_provider_cancel_request(msg->chat_room->lc->http_provider, msg->http_request); - if (msg->dir == LinphoneChatMessageOutgoing) { + if ((msg->dir == LinphoneChatMessageOutgoing) && unref) { // must release it linphone_chat_message_unref(msg); } @@ -639,6 +639,10 @@ void linphone_chat_message_cancel_file_transfer(LinphoneChatMessage *msg) { } } +void linphone_chat_message_cancel_file_transfer(LinphoneChatMessage *msg) { + _linphone_chat_message_cancel_file_transfer(msg, TRUE); +} + void linphone_chat_message_set_file_transfer_filepath(LinphoneChatMessage *msg, const char *filepath) { if (msg->file_transfer_filepath != NULL) { ms_free(msg->file_transfer_filepath); diff --git a/coreapi/private.h b/coreapi/private.h index 33d8b9710..a43cb2713 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -657,6 +657,7 @@ void linphone_chat_message_set_state(LinphoneChatMessage *msg, LinphoneChatMessa void linphone_chat_message_set_is_secured(LinphoneChatMessage *msg, bool_t secured); void linphone_chat_message_send_delivery_notification(LinphoneChatMessage *cm, LinphoneReason reason); void linphone_chat_message_send_display_notification(LinphoneChatMessage *cm); +void _linphone_chat_message_cancel_file_transfer(LinphoneChatMessage *msg, bool_t unref); int linphone_chat_room_upload_file(LinphoneChatMessage *msg); void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg); LinphoneChatMessageCbs *linphone_chat_message_cbs_new(void); diff --git a/tester/message_tester.c b/tester/message_tester.c index 3f4616c38..cece23af6 100644 --- a/tester/message_tester.c +++ b/tester/message_tester.c @@ -1793,9 +1793,8 @@ void file_transfer_io_error_base(char *server_url, bool_t destroy_room) { linphone_chat_room_send_chat_message(chatroom, msg); BC_ASSERT_TRUE(wait_for_until(marie->lc, NULL, &marie->stat.number_of_LinphoneMessageInProgress, 1, 1000)); if (destroy_room) { - //since message is orphan, we do not expect to be notified of state change linphone_core_delete_chat_room(marie->lc, chatroom); - BC_ASSERT_FALSE(wait_for_until(marie->lc, NULL, &marie->stat.number_of_LinphoneMessageNotDelivered, 1, 1000)); + BC_ASSERT_TRUE(wait_for_until(marie->lc, NULL, &marie->stat.number_of_LinphoneMessageNotDelivered, 1, 1000)); } else { BC_ASSERT_TRUE(wait_for_until(marie->lc, NULL, &marie->stat.number_of_LinphoneMessageNotDelivered, 1, 3000)); }