Fix possible static analysis issue 18/257518/2
authorJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 27 Apr 2021 06:14:28 +0000 (15:14 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 27 Apr 2021 06:39:36 +0000 (15:39 +0900)
- Fix static analysis issue.
- Integrate error check logic for efficiency.

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

index 801318b..00dc535 100644 (file)
@@ -97,7 +97,8 @@ static int _pkgmgrinfo_get_appinfo(const char *appid, uid_t uid,
                return ret;
        }
 
-       if (!g_hash_table_size(list)) {
+       if (!g_hash_table_size(list) || !g_hash_table_lookup(list, appid) ||
+               ((application_x *)g_hash_table_lookup(list, appid))->package == NULL) {
                _LOGD("appinfo for [%s] is not existed for user [%d]",
                                appid, uid);
                g_hash_table_destroy(list);
@@ -112,13 +113,6 @@ static int _pkgmgrinfo_get_appinfo(const char *appid, uid_t uid,
        }
 
        info->app_info = (application_x *)g_hash_table_lookup(list, appid);
-       if (!info->app_info || !info->app_info->package) {
-               _LOGD("appinfo for [%s] is not existed for user [%d]",
-                               appid, uid);
-               g_hash_table_destroy(list);
-               free(info);
-               return PMINFO_R_ENOENT;
-       }
        info->locale = strdup(info->app_info->locale);
        if (!info->locale) {
                _LOGE("out of memory");
index 315166d..4e78ca1 100644 (file)
@@ -200,7 +200,7 @@ static int _pkgmgrinfo_get_pkginfo(const char *pkgid, uid_t uid,
                return ret;
        }
 
-       if (!g_hash_table_size(list)) {
+       if (!g_hash_table_size(list) || !g_hash_table_lookup(list, pkgid)) {
                _LOGD("pkginfo for [%s] is not existed for user [%d]",
                                pkgid, uid);
                g_hash_table_destroy(list);