From: Kyeonghun Lee Date: Thu, 12 May 2016 05:53:21 +0000 (+0900) Subject: wrong memory alloc issue fixed X-Git-Tag: submit/tizen/20160516.023257^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=049e424aecb932b4c806c73282553543b9b3b04e;p=platform%2Fcore%2Fapi%2Fmessages.git wrong memory alloc issue fixed Change-Id: I4512cd7cb25aac3562c1f20e7d0717f12f1fdc9b Signed-off-by: Kyeonghun Lee --- diff --git a/src/messages.c b/src/messages.c index ce9f840..9bf681f 100644 --- a/src/messages.c +++ b/src/messages.c @@ -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;