From 2b93067a78a0373f24ee868d5bd0523f6be15d14 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Fri, 9 Jun 2017 14:16:34 +0200 Subject: [PATCH] fix memory leak and crash in test suite --- coreapi/chat.c | 2 +- tester/message_tester.c | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/coreapi/chat.c b/coreapi/chat.c index 029884103..19b49caf0 100644 --- a/coreapi/chat.c +++ b/coreapi/chat.c @@ -1098,7 +1098,7 @@ static void linphone_chat_room_send_is_composing_notification(LinphoneChatRoom * msg = linphone_chat_room_create_message(cr, content); linphone_chat_message_set_from_address(msg, from_addr); linphone_chat_message_set_to_address(msg, to_addr); - msg->content_type = ms_strdup("application/im-iscomposing+xml"); + linphone_chat_message_set_content_type(msg, "application/im-iscomposing+xml"); if (imee) { LinphoneImEncryptionEngineCbs *imee_cbs = linphone_im_encryption_engine_get_callbacks(imee); diff --git a/tester/message_tester.c b/tester/message_tester.c index e6df3c71e..d9b76fc48 100644 --- a/tester/message_tester.c +++ b/tester/message_tester.c @@ -2308,7 +2308,7 @@ static int im_encryption_engine_process_incoming_message_cb(LinphoneImEncryption ms_free (msg->message); output[b64Size] = '\0'; msg->message = (char *)output; - msg->content_type = ms_strdup("text/plain"); + linphone_chat_message_set_content_type(msg, "text/plain"); return 0; } else if (strcmp(msg->content_type, "text/plain") == 0) { return -1; // Not encrypted, nothing to do @@ -2321,16 +2321,15 @@ static int im_encryption_engine_process_incoming_message_cb(LinphoneImEncryption static int im_encryption_engine_process_outgoing_message_cb(LinphoneImEncryptionEngine *engine, LinphoneChatRoom *room, LinphoneChatMessage *msg) { if (strcmp(msg->content_type,"text/plain") == 0) { - size_t b64Size; + size_t b64Size = 0; unsigned char *output; bctbx_base64_encode(NULL, &b64Size, (unsigned char *)msg->message, strlen(msg->message)); - output = (unsigned char *)ms_malloc(b64Size+1), + output = (unsigned char *)ms_malloc0(b64Size+1), bctbx_base64_encode(output, &b64Size, (unsigned char *)msg->message, strlen(msg->message)); ms_free (msg->message); output[b64Size] = '\0'; msg->message = (char *)output; - ms_free(msg->content_type); - msg->content_type = ms_strdup("cipher/b64"); + linphone_chat_message_set_content_type(msg, "cipher/b64"); return 0; } return -1;