wrong memory alloc issue fixed 87/69187/2 accepted/tizen/common/20160516.143402 accepted/tizen/ivi/20160516.091619 accepted/tizen/mobile/20160516.091637 accepted/tizen/wearable/20160516.091646 submit/tizen/20160516.023257
authorKyeonghun Lee <kh9090.lee@samsung.com>
Thu, 12 May 2016 05:53:21 +0000 (14:53 +0900)
committerKyeonghun Lee <kh9090.lee@samsung.com>
Thu, 12 May 2016 06:03:18 +0000 (15:03 +0900)
Change-Id: I4512cd7cb25aac3562c1f20e7d0717f12f1fdc9b
Signed-off-by: Kyeonghun Lee <kh9090.lee@samsung.com>
src/messages.c

index ce9f840..9bf681f 100644 (file)
@@ -593,13 +593,13 @@ int messages_search_message(messages_service_h service, messages_message_box_e m
        int i;
        int ret;
 
-       msg_struct_list_s msg_list;
+       msg_struct_list_s msg_list = {0,};
        msg_struct_t listCond;
        messages_message_type_e _msgType;
 
        messages_service_s *_svc = (messages_service_s *) service;
        messages_message_s *_msg = NULL;
-       messages_message_h *_array;
+       messages_message_h *_array = NULL;
 
        CHECK_NULL(_svc);
        CHECK_NULL(message_array);
@@ -630,36 +630,39 @@ int messages_search_message(messages_service_h service, messages_message_box_e m
                msg_release_list_struct(&msg_list);
                return ERROR_CONVERT(ret);
        }
-       /* Result */
-       _array = (messages_message_h *) calloc(msg_list.nCount + 1, sizeof(messages_message_h));
-       if (NULL == _array) {
-               msg_release_list_struct(&msg_list);
-               LOGE("[%s:%d] OUT_OF_MEMORY(0x%08x) fail to create '_array'.", __FUNCTION__, __LINE__, MESSAGES_ERROR_OUT_OF_MEMORY);
-               return MESSAGES_ERROR_OUT_OF_MEMORY;
-       }
 
-       for (i = 0; i < msg_list.nCount; i++) {
-               _msg = (messages_message_s *) calloc(1, sizeof(messages_message_s));
-               if (NULL == _msg) {
-                       LOGE("[%s:%d] OUT_OF_MEMORY(0x%08x) fail to create '_msg'.", __FUNCTION__, __LINE__, MESSAGES_ERROR_OUT_OF_MEMORY);
-                       for (; i > 0; i--)
-                               free(_array[i - 1]);
-
-                       free(_array);
+       /* Result */
+       if (msg_list.nCount > 0) {
+               _array = (messages_message_h *) calloc(msg_list.nCount + 1, sizeof(messages_message_h));
+               if (NULL == _array) {
                        msg_release_list_struct(&msg_list);
+                       LOGE("[%s:%d] OUT_OF_MEMORY(0x%08x) fail to create '_array'.", __FUNCTION__, __LINE__, MESSAGES_ERROR_OUT_OF_MEMORY);
                        return MESSAGES_ERROR_OUT_OF_MEMORY;
                }
 
-               _msg->text = NULL;
-               _msg->attachment_list = NULL;
-               _msg->msg_h = msg_list.msg_struct_info[i];
+               for (i = 0; i < msg_list.nCount; i++) {
+                       _msg = (messages_message_s *) calloc(1, sizeof(messages_message_s));
+                       if (NULL == _msg) {
+                               LOGE("[%s:%d] OUT_OF_MEMORY(0x%08x) fail to create '_msg'.", __FUNCTION__, __LINE__, MESSAGES_ERROR_OUT_OF_MEMORY);
+                               for (; i > 0; i--)
+                                       free(_array[i - 1]);
 
-               messages_get_message_type((messages_message_h) _msg, &_msgType);
+                               free(_array);
+                               msg_release_list_struct(&msg_list);
+                               return MESSAGES_ERROR_OUT_OF_MEMORY;
+                       }
 
-               if (IS_MMS(_msgType))
-                       _messages_load_mms_data(_msg, _svc->service_h);
+                       _msg->text = NULL;
+                       _msg->attachment_list = NULL;
+                       _msg->msg_h = msg_list.msg_struct_info[i];
 
-               _array[i] = (messages_message_h) _msg;
+                       messages_get_message_type((messages_message_h) _msg, &_msgType);
+
+                       if (IS_MMS(_msgType))
+                               _messages_load_mms_data(_msg, _svc->service_h);
+
+                       _array[i] = (messages_message_h) _msg;
+               }
        }
 
        *message_array = (messages_message_h *) _array;