realloc issue fixed 24/103124/1
authorKyeonghun Lee <kh9090.lee@samsung.com>
Wed, 30 Nov 2016 11:49:02 +0000 (20:49 +0900)
committerKyeonghun Lee <kh9090.lee@samsung.com>
Wed, 7 Dec 2016 09:18:59 +0000 (01:18 -0800)
Change-Id: I029c199ef515b004a519bbad37651b5ba5d1f2c4
Signed-off-by: Kyeonghun Lee <kh9090.lee@samsung.com>
(cherry picked from commit fb75ff3b338659a4d4f98ce39c0e53d570f7829f)

src/messages.c

index 140e74c..663a585 100644 (file)
@@ -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;
        }