From 52787d2710a642c5091993aba68e0cbfd17bf7e3 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 1 Dec 2020 11:14:48 +0900 Subject: [PATCH] Add exceptions about memory allocation Change-Id: Ifa398d8094573e98c5aa694b52d6dda35a5393eb Signed-off-by: Hwankyu Jhun --- include/aul_svc.h | 19 ++++++++++--------- src/service.c | 17 +++++++++++++++-- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/include/aul_svc.h b/include/aul_svc.h index 6895f73..5def1df 100644 --- a/include/aul_svc.h +++ b/include/aul_svc.h @@ -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; diff --git a/src/service.c b/src/service.c index f9b4618..6577718 100755 --- a/src/service.c +++ b/src/service.c @@ -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]); -- 2.7.4