summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeungha Son <seungha.son@samsung.com>2017-08-04 11:37:23 +0900
committerMyungKi Lee <mk5004.lee@samsung.com>2017-08-09 04:12:18 +0000
commitd3f9fe4b9e8f02afcf6725e1fb8415b844fa4728 (patch)
tree20f13eb156790877fb6d9d485b60ba5ae3f8fe7a
parent4e7c7ccdecb19742bf846156bff218af85553659 (diff)
downloadnotification-d3f9fe4b9e8f02afcf6725e1fb8415b844fa4728.tar.gz
notification-d3f9fe4b9e8f02afcf6725e1fb8415b844fa4728.tar.bz2
notification-d3f9fe4b9e8f02afcf6725e1fb8415b844fa4728.zip
Add exception handling
- Added exception handling for invalid notifications when creating notification handle is failed Signed-off-by: Seungha Son <seungha.son@samsung.com> Change-Id: Ia79d12e4d0d6b4866ac15866e5ad5da28ffcf27f
-rwxr-xr-xinclude/notification.h1
-rwxr-xr-xsrc/notification.c13
2 files changed, 12 insertions, 2 deletions
diff --git a/include/notification.h b/include/notification.h
index e880b6b..466f624 100755
--- a/include/notification.h
+++ b/include/notification.h
@@ -1070,6 +1070,7 @@ int notification_delete(notification_h noti);
* @exception #NOTIFICATION_ERROR_NONE Success
* @exception #NOTIFICATION_ERROR_INVALID_PARAMETER Invalid input value
* @exception #NOTIFICATION_ERROR_OUT_OF_MEMORY Out of memory
+ * @exception #NOTIFICATION_ERROR_IO_ERROR I/O error
* @see #notification_type_e
* @par Sample code:
* @code
diff --git a/src/notification.c b/src/notification.c
index 2df7b21..f2b92a8 100755
--- a/src/notification.c
+++ b/src/notification.c
@@ -1441,7 +1441,7 @@ static notification_h _notification_create(notification_type_e type)
char *app_root_path = NULL;
char locale_directory[PATH_MAX] = { 0, }; /* PATH_MAX 4096 */
char pkg_id[NOTI_PKG_ID_LEN + 1] = { 0, };
- int err;
+ int err = 0;
if (type <= NOTIFICATION_TYPE_NONE || type > NOTIFICATION_TYPE_MAX) {
NOTIFICATION_ERR("Invalid notification type[%d]", type);
@@ -1475,6 +1475,7 @@ static notification_h _notification_create(notification_type_e type)
noti->caller_app_id = notification_get_app_id_by_pid(getpid());
if (noti->caller_app_id == NULL) {
NOTIFICATION_ERR("Failed to get caller_app_id");
+ err = -1;
goto out;
}
@@ -1524,11 +1525,19 @@ out:
if (package_info)
package_info_destroy(package_info);
+ if (err != 0) {
+ notification_free(noti);
+ noti = NULL;
+ set_last_result(NOTIFICATION_ERROR_IO_ERROR);
+ } else {
+ set_last_result(NOTIFICATION_ERROR_NONE);
+ }
+
/*!
* \NOTE
* Other fields are already initialized with ZERO.
*/
- set_last_result(NOTIFICATION_ERROR_NONE);
+
return noti;
}