diff options
-rw-r--r-- | src/messages.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/messages.c b/src/messages.c index 140e74c..663a585 100644 --- a/src/messages.c +++ b/src/messages.c @@ -798,6 +798,10 @@ void _messages_incoming_mediator_cb(msg_handle_t handle, msg_struct_t msg, void ((messages_incoming_cb) _svc->incoming_cb) ((messages_message_h) _msg, _svc->incoming_cb_user_data); messages_mms_remove_all_attachments((messages_message_h) _msg); + if (_msg->text) { + free(_msg->text); + _msg->text = NULL; + } free(_msg); } } @@ -1627,7 +1631,10 @@ int _messages_load_mms_data(messages_message_s * msg, msg_handle_t handle) msg_get_str_value(mms_media, MSG_MMS_MEDIA_FILEPATH_STR, filepath, MSG_FILEPATH_LEN_MAX); if (MMS_SMIL_MEDIA_TEXT == media_type) { - _messages_load_textfile(filepath, &msg->text); + if (_messages_load_textfile(filepath, &msg->text) != 0) { + LOGW("[%s:%d] OPERATION_FAILED(0x%08x) : _messages_load_textfile failed.", __FUNCTION__, __LINE__, MESSAGES_ERROR_OPERATION_FAILED); + break; + } } else { attach = (messages_attachment_s *) calloc(1, sizeof(messages_attachment_s)); if (NULL == attach) { @@ -1713,6 +1720,7 @@ int _messages_load_textfile(const char *filepath, char **text) struct stat st; size_t nread, len; char *pos; + char *temp = NULL; CHECK_NULL(filepath); @@ -1738,11 +1746,12 @@ int _messages_load_textfile(const char *filepath, char **text) pos = *text; } else { len = strlen(*text); - *text = (char *)realloc(*text, len + st.st_size + 2); - if (*text == NULL) { + temp = (char *)realloc(*text, len + st.st_size + 2); + if (temp == NULL) { fclose(file); return MESSAGES_ERROR_OPERATION_FAILED; } + *text = temp; (*text)[len] = '\n'; pos = *text + len + 1; } |