From: Jusung Son Date: Fri, 12 Jul 2019 00:59:38 +0000 (+0900) Subject: Add exception handling codes X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=44cc607644af1d5b13bb2d75fd24a0a91ff79fdd;p=platform%2Fcore%2Fapi%2Fnotification.git Add exception handling codes Change-Id: Id21db779d4b121206299d69b38756245f5e12c05 Signed-off-by: Jusung Son --- diff --git a/notification-ex/stub.cc b/notification-ex/stub.cc index 341c2e87..6eb09339 100644 --- a/notification-ex/stub.cc +++ b/notification-ex/stub.cc @@ -932,10 +932,22 @@ extern "C" EXPORT_API int noti_ex_item_input_selector_get_contents( InputSelectorItem* p = static_cast(h->Get()); list contents = p->GetContents(); char **list = (char**)calloc(contents.size(), sizeof(char*)); + if (list == nullptr) { + LOGE("Out of memory"); + return NOTI_EX_ERROR_OUT_OF_MEMORY; + } + int idx = 0; for (auto& i : contents) { - list[idx++] = strdup(i.c_str()); + list[idx] = strdup(i.c_str()); + if (list[idx] == nullptr) { + __noti_ex_free_str_array(list, idx); + LOGE("Out of memory"); + return NOTI_EX_ERROR_OUT_OF_MEMORY; + } + idx++; } + *count = contents.size(); *contents_list = list; @@ -1576,11 +1588,24 @@ extern "C" EXPORT_API int noti_ex_item_get_shared_paths(noti_ex_item_h handle, } Handle* p = static_cast(handle); list shared_path = p->Get()->GetSharedPath(); - *path = (char**)calloc(shared_path.size(), sizeof(char*)); + char** tmp_path = (char**)calloc(shared_path.size(), sizeof(char*)); + if (tmp_path == nullptr) { + LOGE("Fail to create items"); + return NOTI_EX_ERROR_OUT_OF_MEMORY; + } + int idx = 0; for (auto& i : shared_path) { - *path[idx++] = strdup(i.c_str()); + tmp_path[idx] = strdup(i.c_str()); + if (tmp_path[idx] == nullptr) { + __noti_ex_free_str_array(tmp_path, idx); + LOGE("Out of memory"); + return NOTI_EX_ERROR_OUT_OF_MEMORY; + } + idx++; } + + *path = tmp_path; *count = shared_path.size(); return NOTI_EX_ERROR_NONE; } @@ -1744,11 +1769,24 @@ extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle, Handle* p = static_cast(handle); list receivers = p->Get()->GetReceiverList(); - *receiver_list = (char**)calloc(receivers.size(), sizeof(char*)); + char **tmp_list = (char**)calloc(receivers.size(), sizeof(char*)); + if (tmp_list == nullptr) { + LOGE("Out of memory"); + return NOTI_EX_ERROR_OUT_OF_MEMORY; + } + int idx = 0; for (auto& i : receivers) { - *receiver_list[idx++] = strdup(i.c_str()); + tmp_list[idx] = strdup(i.c_str()); + if (tmp_list[idx] == nullptr) { + __noti_ex_free_str_array(tmp_list, idx); + LOGE("Out of memory"); + return NOTI_EX_ERROR_OUT_OF_MEMORY; + } + idx++; } + + *receiver_list = tmp_list; *count = receivers.size(); return NOTI_EX_ERROR_NONE; }