Separate null check routine
authorJunghyun Yeon <jungh.yeon@samsung.com>
Wed, 3 Mar 2021 02:47:27 +0000 (11:47 +0900)
committer연정현/Tizen Platform Lab(SR)/Staff Engineer/삼성전자 <jungh.yeon@samsung.com>
Wed, 3 Mar 2021 04:04:00 +0000 (13:04 +0900)
Both could be failed due to short of memory.

Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/pkgmgrinfo_appinfo.c

index 1ee2e81..1a96556 100644 (file)
@@ -91,7 +91,7 @@ static int _pkgmgrinfo_get_appinfo(const char *appid, uid_t uid,
                return PMINFO_R_ERROR;
 
        // TODO: need to use pkginfo-client APIs
-       ret = _appinfo_get_applications(uid, uid, filter, 
+       ret = _appinfo_get_applications(uid, uid, filter,
                        PMINFO_APPINFO_GET_ALL, list);
        if (ret != PMINFO_R_OK) {
                g_hash_table_destroy(list);
@@ -121,11 +121,16 @@ static int _pkgmgrinfo_get_appinfo(const char *appid, uid_t uid,
                return PMINFO_R_ENOENT;
        }
        info->locale = strdup(info->app_info->locale);
+       if (!info->locale) {
+               _LOGE("out of memory");
+               g_hash_table_destroy(list);
+               free(info);
+               return PMINFO_R_ERROR;
+       }
        info->package = strdup(info->app_info->package);
-       if (!info->package || !info->locale) {
+       if (!info->package) {
                _LOGE("out of memory");
-               if (info->locale)
-                       free(info->locale);
+               free(info->locale);
                g_hash_table_destroy(list);
                free(info);
                return PMINFO_R_ERROR;
@@ -624,7 +629,7 @@ static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
        if (list == NULL)
                return PMINFO_R_ERROR;
 
-       ret = _appinfo_get_applications(uid, uid, filter, 
+       ret = _appinfo_get_applications(uid, uid, filter,
                        flag | PMINFO_APPINFO_GET_BASICINFO, list);
        if (ret != PMINFO_R_OK) {
                g_hash_table_destroy(list);
@@ -1505,7 +1510,7 @@ API int pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(
                return PMINFO_R_EINVAL;
        }
 
-       ret = _appinfo_get_datacontrol_trusted_info(providerid, type, uid, 
+       ret = _appinfo_get_datacontrol_trusted_info(providerid, type, uid,
                        appid, &trusted);
 
        /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
@@ -1647,7 +1652,7 @@ API int pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(const char *appid,
                return PMINFO_R_EINVAL;
        }
 
-       ret = _appinfo_get_appcontrol_privileges(appid, operation, uid, 
+       ret = _appinfo_get_appcontrol_privileges(appid, operation, uid,
                        &privilege_list);
        if (ret == PMINFO_R_ENOENT) {
                return PMINFO_R_OK;
@@ -1656,7 +1661,7 @@ API int pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(const char *appid,
                return ret;
        }
 
-       for (tmp_list = privilege_list; tmp_list != NULL; 
+       for (tmp_list = privilege_list; tmp_list != NULL;
                        tmp_list = g_list_next(tmp_list)) {
                ret = privilege_func((char *)tmp_list->data, user_data);
                if (ret != 0)