fix leaks

This commit is contained in:
Gautier Pelloux-Prayer 2016-07-19 11:56:58 +02:00
parent e532736526
commit dce962bf58
5 changed files with 62 additions and 52 deletions

View file

@ -466,7 +466,7 @@ void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatMessage
}
linphone_chat_room_delete_composing_idle_timer(cr);
linphone_chat_room_delete_composing_refresh_timer(cr);
if (call && call->op == op) {
/*In this case, chat delivery status is not notified, so unrefing chat message right now*/
/*Might be better fixed by delivering status, but too costly for now*/
@ -475,7 +475,7 @@ void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatMessage
linphone_chat_message_unref(msg);
return;
}
}
// if operation failed, we should not change message state

View file

@ -49,27 +49,30 @@ static void _release_http_request(LinphoneChatMessage* msg) {
static void linphone_chat_message_process_io_error_upload(void *data, const belle_sip_io_error_event_t *event) {
LinphoneChatMessage *msg = (LinphoneChatMessage *)data;
ms_error("I/O Error during file upload of msg [%p]", msg);
linphone_chat_message_set_state(msg, LinphoneChatMessageStateNotDelivered);
linphone_chat_message_update_state(msg, LinphoneChatMessageStateNotDelivered);
_release_http_request(msg);
linphone_chat_message_unref(msg);
}
static void linphone_chat_message_process_auth_requested_upload(void *data, belle_sip_auth_event_t *event) {
LinphoneChatMessage *msg = (LinphoneChatMessage *)data;
ms_error("Error during file upload: auth requested for msg [%p]", msg);
linphone_chat_message_set_state(msg, LinphoneChatMessageStateNotDelivered);
linphone_chat_message_update_state(msg, LinphoneChatMessageStateNotDelivered);
_release_http_request(msg);
linphone_chat_message_unref(msg);
}
static void linphone_chat_message_process_io_error_download(void *data, const belle_sip_io_error_event_t *event) {
LinphoneChatMessage *msg = (LinphoneChatMessage *)data;
ms_error("I/O Error during file download msg [%p]", msg);
linphone_chat_message_set_state(msg, LinphoneChatMessageStateFileTransferError);
linphone_chat_message_update_state(msg, LinphoneChatMessageStateFileTransferError);
_release_http_request(msg);
}
static void linphone_chat_message_process_auth_requested_download(void *data, belle_sip_auth_event_t *event) {
LinphoneChatMessage *msg = (LinphoneChatMessage *)data;
ms_error("Error during file download : auth requested for msg [%p]", msg);
linphone_chat_message_set_state(msg, LinphoneChatMessageStateFileTransferError);
linphone_chat_message_update_state(msg, LinphoneChatMessageStateFileTransferError);
_release_http_request(msg);
}
@ -577,6 +580,10 @@ 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) {
// must release it
linphone_chat_message_unref(msg);
}
} else {
ms_message("Warning: http request still running for ORPHAN msg [%p]: this is a memory leak", msg);
}

2
oRTP

@ -1 +1 @@
Subproject commit e7ae3587d3b7638a59c0929b332a50b78d84aa1c
Subproject commit e3ed91f4937ba972046ac084c0c856cafaa0b4d3

View file

@ -229,7 +229,7 @@ int main (int argc, char *argv[])
#endif
liblinphone_tester_init(NULL);
linphone_core_set_log_level(ORTP_FATAL);
linphone_core_set_log_level(ORTP_ERROR);
for(i = 1; i < argc; ++i) {
if (strcmp(argv[i], "--verbose") == 0) {

View file

@ -634,23 +634,23 @@ static void file_transfer_2_messages_simultaneously(void) {
}
ms_error("%s", buf);
}
cbs = linphone_chat_message_get_callbacks(msg);
linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed);
linphone_chat_message_cbs_set_file_transfer_recv(cbs, file_transfer_received);
linphone_chat_message_download_file(msg);
cbs = linphone_chat_message_get_callbacks(msg2);
linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed);
linphone_chat_message_cbs_set_file_transfer_recv(cbs, file_transfer_received);
linphone_chat_message_download_file(msg2);
BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneFileTransferDownloadSuccessful,2));
BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,4, int, "%d");
BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageDelivered,2, int, "%d");
compare_files(send_filepath, receive_filepath);
linphone_chat_message_unref(msg);
}
}
@ -986,10 +986,10 @@ static void lime_unit(void) {
uint8_t receiverZID[12];
xmlDocPtr cacheBuffer;
FILE *CACHE;
/**** Low level tests using on cache file to extract keys, encrypt/decrypt ****/
/**** use functions that are not directly used by external entities ****/
/* create and load cache file */
CACHE = fopen_from_write_dir("ZIDCache.xml", "wb");
fprintf (CACHE, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<cache><selfZID>ef7692d0792a67491ae2d44e</selfZID><peer><ZID>005dbe0399643d953a2202dd</ZID><rs1>9b5c8f06f3b6c2c695f2dfc3c26f31f5fef8661f8c5fe7c95aeb5c5b0435b045</rs1><aux>f8324dd18ea905171ec2be89f879d01d5994132048d92ea020778cbdf31c605e</aux><rs2>2fdcef69380937c2cf221f7d11526f286c39f49641452ba9012521c705094899</rs2><uri>pipo1@pipo.com</uri><sndKey>963c57bb28e62068d2df23e8f9b771932d3c57bb28e62068d2df23e8f9b77193</sndKey><rcvKey>05d9ac653a83c4559cb0ae7394e7cd3b2d3c57bb28e62068d2df23e8f9b77193</rcvKey><sndSId>5f9aa1e5e4c7ec88fa389a9f6b8879b42d3c57bb28e62068d2df23e8f9b77193</sndSId><rcvSId>02ffd51e7316a6c6f53a50fcf01b01bf2d3c57bb28e62068d2df23e8f9b77193</rcvSId><sndIndex>00000069</sndIndex><rcvIndex>000001e8</rcvIndex><pvs>01</pvs></peer><peer><ZID>1234567889643d953a2202ee</ZID><rs1>9b5c8f06f3b6c2c695f2dfc3c26f31f5fef8661f8c5fe7c95aeb5c5b0435b045</rs1><aux>f8324dd18ea905171ec2be89f879d01d5994132048d92ea020778cbdf31c605e</aux><rs2>2fdcef69380937c2cf221f7d11526f286c39f49641452ba9012521c705094899</rs2><uri>pipo1@pipo.com</uri><sndKey>123456789012345678901234567890123456765431262068d2df23e8f9b77193</sndKey><rcvKey>25d9ac653a83c4559cb0ae7394e7cd3b2d3c57bb28e62068d2df23e8f9b77193</rcvKey><sndSId>f69aa1e5e4c7ec88fa389a9f6b8879b42d3c57bb28e62068d2df23e8f9b77193</sndSId><rcvSId>22ffd51e7316a6c6f53a50fcf01b01bf2d3c57bb28e62068d2df23e8f9b77193</rcvSId><sndIndex>00000001</sndIndex><rcvIndex>00000000</rcvIndex><pvs>01</pvs></peer></cache>");
@ -1001,7 +1001,7 @@ static void lime_unit(void) {
/* parse it to an xmlDoc */
cacheBuffer = xmlParseDoc(cacheBufferString);
ms_free(cacheBufferString);
/* get data from cache : sender */
associatedKeys.peerURI = (uint8_t *)malloc(15);
memcpy(associatedKeys.peerURI, "pipo1@pipo.com", 15);
@ -1010,14 +1010,14 @@ static void lime_unit(void) {
BC_ASSERT_EQUAL(retval, 0, int, "%d");
BC_ASSERT_EQUAL(associatedKeys.associatedZIDNumber, 2, int, "%d"); /* there are 2 keys associated to pipo1@pipo.com address in the cache above*/
ms_message("Get cached key by URI, for sender, return %d keys", associatedKeys.associatedZIDNumber);
for (i=0; i<associatedKeys.associatedZIDNumber; i++) {
printHex("ZID", associatedKeys.peerKeys[i]->peerZID, 12);
printHex("key", associatedKeys.peerKeys[i]->key, 32);
printHex("sessionID", associatedKeys.peerKeys[i]->sessionId, 32);
ms_message("session index %d\n", associatedKeys.peerKeys[i]->sessionIndex);
}
/* get data from cache : receiver */
memcpy(associatedKey.peerZID, targetZID, 12);
retval = lime_getCachedRcvKeyByZid(cacheBuffer, &associatedKey);
@ -1026,7 +1026,7 @@ static void lime_unit(void) {
printHex("Key", associatedKey.key, 32);
printHex("sessionID", associatedKey.sessionId, 32);
ms_message("session index %d\n", associatedKey.sessionIndex);
/* encrypt/decrypt a msg */
lime_encryptMessage(associatedKeys.peerKeys[0], (uint8_t *)PLAIN_TEXT_TEST_MESSAGE, (uint32_t)strlen(PLAIN_TEXT_TEST_MESSAGE), senderZID, encryptedMessage);
printHex("Ciphered", encryptedMessage, strlen((char *)encryptedMessage));
@ -1037,24 +1037,24 @@ static void lime_unit(void) {
BC_ASSERT_EQUAL(retval, 0, int, "%d");
BC_ASSERT_STRING_EQUAL((char *)plainMessage, (char *)PLAIN_TEXT_TEST_MESSAGE);
ms_message("Decrypt and auth returned %d\nPlain text is %s\n", retval, plainMessage);
/* update receiver data */
associatedKey.sessionIndex++;
associatedKey.key[0]++;
associatedKey.sessionId[0]++;
retval = lime_setCachedKey(cacheBuffer, &associatedKey, LIME_RECEIVER);
BC_ASSERT_EQUAL(retval, 0, int, "%d");
/* update sender data */
associatedKeys.peerKeys[0]->sessionIndex++;
associatedKeys.peerKeys[0]->key[0]++;
associatedKeys.peerKeys[0]->sessionId[0]++;
retval = lime_setCachedKey(cacheBuffer, associatedKeys.peerKeys[0], LIME_SENDER);
BC_ASSERT_EQUAL(retval, 0, int, "%d");
/* free memory */
lime_freeKeys(&associatedKeys);
/* write the file */
/* dump the xml document into a string */
xmlDocDumpFormatMemoryEnc(cacheBuffer, &xmlStringOutput, &xmlStringLength, "UTF-8", 0);
@ -1064,7 +1064,7 @@ static void lime_unit(void) {
xmlFree(xmlStringOutput);
fclose(CACHE);
xmlFreeDoc(cacheBuffer);
/**** Higher level tests using 2 caches to encrypt/decrypt a msg ****/
/* Create Alice cache file and then load it */
CACHE = fopen_from_write_dir("ZIDCacheAlice.xml", "wb");
@ -1077,7 +1077,7 @@ static void lime_unit(void) {
/* parse it to an xmlDoc */
cacheBufferAlice = xmlParseDoc(cacheBufferString);
ms_free(cacheBufferString);
/* Create Bob cache file and then load it */
CACHE = fopen_from_write_dir("ZIDCacheBob.xml", "wb");
fprintf(CACHE, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<cache><selfZID>005dbe0399643d953a2202dd</selfZID><peer><ZID>ef7692d0792a67491ae2d44e</ZID><rs1>9b5c8f06f3b6c2c695f2dfc3c26f31f5fef8661f8c5fe7c95aeb5c5b0435b045</rs1><aux>f8324dd18ea905171ec2be89f879d01d5994132048d92ea020778cbdf31c605e</aux><rs2>2fdcef69380937c2cf221f7d11526f286c39f49641452ba9012521c705094899</rs2><uri>sip:marie@sip.example.org</uri><rcvKey>9111ebeb52e50edcc6fcb3eea1a2d3ae3c2c75d3668923e83c59d0f472455150</rcvKey><sndKey>60f020a3fe11dc2cc0e1e8ed9341b4cd14944db806ca4fc95456bbe45d95c43a</sndKey><rcvSId>5f9aa1e5e4c7ec88fa389a9f6b8879b42d3c57bb28e62068d2df23e8f9b77193</rcvSId><sndSId>bcffd51e7316a6c6f53a50fcf01b01bf2d3c57bb28e62068d2df23e8f9b77193</sndSId><rcvIndex>00000080</rcvIndex><sndIndex>000001cf</sndIndex><pvs>01</pvs></peer><peer><ZID>1234567889643d953a2202ee</ZID><rs1>9b5c8f06f3b6c2c695f2dfc3c26f31f5fef8661f8c5fe7c95aeb5c5b0435b045</rs1><aux>f8324dd18ea905171ec2be89f879d01d5994132048d92ea020778cbdf31c605e</aux><rs2>2fdcef69380937c2cf221f7d11526f286c39f49641452ba9012521c705094899</rs2><uri>sip:marie@sip.example.org</uri><sndKey>81e6e6362c34dc974263d1f77cbb9a8d6d6a718330994379099a8fa19fb12faa</sndKey><rcvKey>25d9ac653a83c4559cb0ae7394e7cd3b2d3c57bb28e62068d2df23e8f9b77193</rcvKey><sndSId>f69aa1e5e4c7ec88fa389a9f6b8879b42d3c57bb28e62068d2df23e8f9b77193</sndSId><rcvSId>22ffd51e7316a6c6f53a50fcf01b01bf2d3c57bb28e62068d2df23e8f9b77193</rcvSId><sndIndex>0000002e</sndIndex><rcvIndex>00000000</rcvIndex><pvs>01</pvs></peer></cache>");
@ -1089,20 +1089,20 @@ static void lime_unit(void) {
/* parse it to an xmlDoc */
cacheBufferBob = xmlParseDoc(cacheBufferString);
ms_free(cacheBufferString);
/* encrypt a msg */
retval = lime_createMultipartMessage(cacheBufferAlice, (uint8_t *)PLAIN_TEXT_TEST_MESSAGE, (uint8_t *)"sip:pauline@sip.example.org", &multipartMessage);
BC_ASSERT_EQUAL(retval, 0, int, "%d");
if (retval == 0) {
ms_message("Encrypted msg created is %s", multipartMessage);
}
/* decrypt the multipart msg */
retval = lime_decryptMultipartMessage(cacheBufferBob, multipartMessage, &decryptedMessage);
BC_ASSERT_EQUAL(retval, 0, int, "%d");
if (retval == 0) {
BC_ASSERT_STRING_EQUAL((char *)decryptedMessage, (char *)PLAIN_TEXT_TEST_MESSAGE);
@ -1110,7 +1110,7 @@ static void lime_unit(void) {
}
free(multipartMessage);
free(decryptedMessage);
/* update ZID files */
/* dump the xml document into a string */
xmlDocDumpFormatMemoryEnc(cacheBufferAlice, &xmlStringOutput, &xmlStringLength, "UTF-8", 0);
@ -1119,15 +1119,15 @@ static void lime_unit(void) {
fwrite(xmlStringOutput, 1, xmlStringLength, CACHE);
xmlFree(xmlStringOutput);
fclose(CACHE);
xmlDocDumpFormatMemoryEnc(cacheBufferBob, &xmlStringOutput, &xmlStringLength, "UTF-8", 0);
/* write it to the file */
CACHE = fopen_from_write_dir("ZIDCacheBob.xml", "wb+");
fwrite(xmlStringOutput, 1, xmlStringLength, CACHE);
xmlFree(xmlStringOutput);
fclose(CACHE);
xmlFreeDoc(cacheBufferAlice);
xmlFreeDoc(cacheBufferBob);
} else {
@ -1352,6 +1352,19 @@ static void text_status_after_destroying_chat_room(void) {
linphone_core_manager_destroy(marie);
}
static void file_transfer_not_sent_if_invalid_url(void) {
LinphoneCoreManager *marie = linphone_core_manager_new("marie_rc");
LinphoneChatRoom *chatroom = linphone_core_get_chat_room_from_uri(marie->lc, "<sip:Jehan@sip.linphone.org>");
LinphoneChatMessage *msg = create_message_from_nowebcam(chatroom);
LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(msg);
linphone_chat_message_cbs_set_msg_state_changed(cbs,liblinphone_tester_chat_message_msg_state_changed);
linphone_core_set_file_transfer_server(marie->lc, "INVALID URL");
linphone_chat_room_send_chat_message(chatroom, msg);
BC_ASSERT_TRUE(wait_for_until(marie->lc, NULL, &marie->stat.number_of_LinphoneMessageNotDelivered, 1, 1000));
linphone_core_manager_destroy(marie);
}
void file_transfer_io_error_base(char *server_url, bool_t destroy_room) {
LinphoneCoreManager *marie = linphone_core_manager_new("marie_rc");
LinphoneChatRoom *chatroom = linphone_core_get_chat_room_from_uri(marie->lc, "<sip:Jehan@sip.linphone.org>");
@ -1366,25 +1379,13 @@ void file_transfer_io_error_base(char *server_url, bool_t destroy_room) {
linphone_core_delete_chat_room(marie->lc, chatroom);
BC_ASSERT_FALSE(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, 1000));
BC_ASSERT_TRUE(wait_for_until(marie->lc, NULL, &marie->stat.number_of_LinphoneMessageNotDelivered, 1, 3000));
}
linphone_core_manager_destroy(marie);
}
static void file_transfer_not_sent_if_invalid_url(void) {
LinphoneCoreManager *marie = linphone_core_manager_new("marie_rc");
LinphoneChatRoom *chatroom = linphone_core_get_chat_room_from_uri(marie->lc, "<sip:Jehan@sip.linphone.org>");
LinphoneChatMessage *msg = create_message_from_nowebcam(chatroom);
LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(msg);
linphone_chat_message_cbs_set_msg_state_changed(cbs,liblinphone_tester_chat_message_msg_state_changed);
linphone_core_set_file_transfer_server(marie->lc, "INVALID URL");
linphone_chat_room_send_chat_message(chatroom, msg);
BC_ASSERT_TRUE(wait_for_until(marie->lc, NULL, &marie->stat.number_of_LinphoneMessageNotDelivered, 1, 1000));
linphone_core_manager_destroy(marie);
}
static void file_transfer_not_sent_if_host_not_found(void) {
file_transfer_io_error_base("https://not_existing_url.com", FALSE);
file_transfer_io_error_base("https://not-existing-url.com", FALSE);
}
static void file_transfer_not_sent_if_url_moved_permanently(void) {
@ -1835,7 +1836,7 @@ test_t message_tests[] = {
TEST_NO_TAG("Transfer message with http proxy", file_transfer_with_http_proxy),
TEST_NO_TAG("Transfer message with upload io error", transfer_message_with_upload_io_error),
TEST_NO_TAG("Transfer message with download io error", transfer_message_with_download_io_error),
TEST_ONE_TAG("Transfer message upload cancelled", transfer_message_upload_cancelled, "LeaksMemory"),
TEST_NO_TAG("Transfer message upload cancelled", transfer_message_upload_cancelled),
TEST_NO_TAG("Transfer message download cancelled", transfer_message_download_cancelled),
TEST_ONE_TAG("Transfer message using external body url", file_transfer_using_external_body_url, "LeaksMemory"),
TEST_NO_TAG("Transfer 2 messages simultaneously", file_transfer_2_messages_simultaneously),
@ -1846,7 +1847,7 @@ test_t message_tests[] = {
TEST_NO_TAG("Lime text message", lime_text_message),
TEST_NO_TAG("Lime text message to non lime", lime_text_message_to_non_lime),
TEST_NO_TAG("Lime transfer message", lime_transfer_message),
TEST_ONE_TAG("Lime transfer message from history", lime_transfer_message_from_history,"LeaksMemory"),
TEST_NO_TAG("Lime transfer message from history", lime_transfer_message_from_history),
TEST_NO_TAG("Lime transfer message without encryption", lime_transfer_message_without_encryption),
TEST_NO_TAG("Lime unitary", lime_unit),
#ifdef SQLITE_STORAGE_ENABLED
@ -1858,13 +1859,15 @@ test_t message_tests[] = {
TEST_NO_TAG("Transfer not sent if invalid url", file_transfer_not_sent_if_invalid_url),
TEST_NO_TAG("Transfer not sent if host not found", file_transfer_not_sent_if_host_not_found),
TEST_NO_TAG("Transfer not sent if url moved permanently", file_transfer_not_sent_if_url_moved_permanently),
TEST_NO_TAG("Transfer io error after destroying chatroom", file_transfer_io_error_after_destroying_chatroom),
TEST_ONE_TAG("Transfer io error after destroying chatroom", file_transfer_io_error_after_destroying_chatroom, "LeaksMemory"),
TEST_ONE_TAG("Real Time Text message", real_time_text_message, "RTT"),
TEST_ONE_TAG("Real Time Text SQL storage", real_time_text_sql_storage, "RTT"),
TEST_ONE_TAG("Real Time Text SQL storage with RTT messages not stored", real_time_text_sql_storage_rtt_disabled, "RTT"),
TEST_ONE_TAG("Real Time Text conversation", real_time_text_conversation, "RTT"),
TEST_ONE_TAG("Real Time Text without audio", real_time_text_without_audio, "RTT"),
#if HAVE_SRTP
TEST_ONE_TAG("Real Time Text with srtp", real_time_text_srtp, "RTT"),
#endif
TEST_ONE_TAG("Real Time Text with ice", real_time_text_ice, "RTT"),
TEST_ONE_TAG("Real Time Text message compatibility crlf", real_time_text_message_compat_crlf, "RTT"),
TEST_ONE_TAG("Real Time Text message compatibility lf", real_time_text_message_compat_lf, "RTT"),