Add exceptions about memory allocation 16/248616/2
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 1 Dec 2020 02:14:48 +0000 (11:14 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 1 Dec 2020 02:48:13 +0000 (11:48 +0900)
Change-Id: Ifa398d8094573e98c5aa694b52d6dda35a5393eb
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
include/aul_svc.h
src/service.c

index 6895f73..5def1df 100644 (file)
@@ -123,15 +123,16 @@ extern "C" {
  * @brief Return values in appsvc.
  */
 typedef enum _aul_svc_return_val {
-       AUL_SVC_RET_ECANCELED = -8,     /**< Operation is canceled */
-       AUL_SVC_RET_EREJECTED = -7,  /**< application launch rejected */
-       AUL_SVC_RET_ETERMINATING = -6,   /**< application terminating */
-       AUL_SVC_RET_EILLACC = -5,        /**< Illegal Access */
-       AUL_SVC_RET_ELAUNCH = -4,        /**< Failure on launching the app */
-       AUL_SVC_RET_ENOMATCH = -3,       /**< No matching result Error */
-       AUL_SVC_RET_EINVAL = -2,         /**< Invalid argument */
-       AUL_SVC_RET_ERROR = -1,          /**< General error */
-       AUL_SVC_RET_OK = 0           /**< General success */
+       AUL_SVC_RET_ENOMEM = -9,        /**< Out of memory */
+       AUL_SVC_RET_ECANCELED = -8,     /**< Operation is canceled */
+       AUL_SVC_RET_EREJECTED = -7,     /**< application launch rejected */
+       AUL_SVC_RET_ETERMINATING = -6,  /**< application terminating */
+       AUL_SVC_RET_EILLACC = -5,       /**< Illegal Access */
+       AUL_SVC_RET_ELAUNCH = -4,       /**< Failure on launching the app */
+       AUL_SVC_RET_ENOMATCH = -3,      /**< No matching result Error */
+       AUL_SVC_RET_EINVAL = -2,        /**< Invalid argument */
+       AUL_SVC_RET_ERROR = -1,         /**< General error */
+       AUL_SVC_RET_OK = 0,             /**< General success */
 } aul_svc_return_val;
 
 
index f9b4618..6577718 100755 (executable)
@@ -1065,8 +1065,14 @@ static int __resolution_post(resolution_info_t *info)
        } else {
                _E("uri_r_info: %s", info->uri_r_info);
                bundle_add(info->b, AUL_SVC_K_URI_R_INFO, info->uri_r_info);
+               info->appid_array = calloc(count, sizeof(char *));
+               if (!info->appid_array) {
+                       _E("Out of memory");
+                       ret = AUL_SVC_RET_ENOMEM;
+                       goto end;
+               }
                info->len = count;
-               info->appid_array = calloc(info->len, sizeof(char *));
+
                iter = info->list;
                while (iter) {
                        info->appid_array[i++] = strdup((char *)iter->data);
@@ -1074,6 +1080,7 @@ static int __resolution_post(resolution_info_t *info)
                }
        }
 
+end:
        __free_pkg_list(info->list);
        __free_resolve_info_data(&info->ri);
        return ret;
@@ -2246,8 +2253,14 @@ API int aul_svc_get_appid_array(bundle *b, uid_t uid, char ***appid_array,
                return AUL_SVC_RET_ERROR;
        }
 
-       *len = arr_len;
        *appid_array = calloc(arr_len, sizeof(char *));
+       if (*appid_array == NULL) {
+               _E("Out of memory");
+               bundle_free(res_b);
+               return AUL_SVC_RET_ENOMEM;
+       }
+       *len = arr_len;
+
        for (i = 0; i < arr_len; ++i)
                (*appid_array)[i] = strdup(str_arr[i]);