Add exception handling 35/142435/4
authorSeungha Son <seungha.son@samsung.com>
Fri, 4 Aug 2017 02:37:23 +0000 (11:37 +0900)
committerMyungKi Lee <mk5004.lee@samsung.com>
Wed, 9 Aug 2017 04:12:18 +0000 (04:12 +0000)
 - Added exception handling for invalid notifications when creating
   notification handle is failed

Signed-off-by: Seungha Son <seungha.son@samsung.com>
Change-Id: Ia79d12e4d0d6b4866ac15866e5ad5da28ffcf27f

include/notification.h
src/notification.c

index e880b6b..466f624 100755 (executable)
@@ -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
index 2df7b21..f2b92a8 100755 (executable)
@@ -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;
 }