diff options
author | Kyeonghun Lee <kh9090.lee@samsung.com> | 2016-05-12 14:53:21 +0900 |
---|---|---|
committer | Kyeonghun Lee <kh9090.lee@samsung.com> | 2016-05-12 15:03:18 +0900 |
commit | 049e424aecb932b4c806c73282553543b9b3b04e (patch) | |
tree | c020abb5fb966ad2c77a93078fbbe9f48bfa1039 | |
parent | dd7e16ea7e0632512a85d5cfa4faa93da94780a9 (diff) | |
download | messages-049e424aecb932b4c806c73282553543b9b3b04e.tar.gz messages-049e424aecb932b4c806c73282553543b9b3b04e.tar.bz2 messages-049e424aecb932b4c806c73282553543b9b3b04e.zip |
wrong memory alloc issue fixedsubmit/tizen/20160516.023257accepted/tizen/wearable/20160516.091646accepted/tizen/mobile/20160516.091637accepted/tizen/ivi/20160516.091619accepted/tizen/common/20160516.143402
Change-Id: I4512cd7cb25aac3562c1f20e7d0717f12f1fdc9b
Signed-off-by: Kyeonghun Lee <kh9090.lee@samsung.com>
-rw-r--r-- | src/messages.c | 51 |
1 files changed, 27 insertions, 24 deletions
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; |