Fix static analyzer issues
[platform/core/appfw/pkgmgr-info.git] / src / pkgmgrinfo_appinfo.c
index a826ec3..0864028 100644 (file)
@@ -160,6 +160,11 @@ static void __parse_appcontrol(GList **appcontrol, char *appcontrol_str)
                return;
 
        dup = strdup(appcontrol_str);
+       if (dup == NULL) {
+               _LOGE("out of memory");
+               return;
+       }
+
        do {
                ac = calloc(1, sizeof(appcontrol_x));
                if (ac == NULL) {
@@ -613,6 +618,8 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
                                                strcasecmp(tmp_record, "false") == 0) {
                                        free(info->is_disabled);
                                        info->is_disabled = tmp_record;
+                               } else {
+                                       free(tmp_record);
                                }
                        }
                        tmp_record = NULL;
@@ -622,6 +629,8 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
                                                strcasecmp(tmp_record, "false") == 0) {
                                        free(info->splash_screen_display);
                                        info->splash_screen_display = tmp_record;
+                               } else {
+                                       free(tmp_record);
                                }
                        }
                }
@@ -721,7 +730,8 @@ static int _pkgmgrinfo_get_appinfo(const char *appid, uid_t uid,
        if (locale == NULL)
                return PMINFO_R_ERROR;
 
-       list = g_hash_table_new(g_str_hash, g_str_equal);
+       list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
+                       __free_applications);
        if (list == NULL) {
                free(locale);
                return PMINFO_R_ERROR;
@@ -733,6 +743,12 @@ static int _pkgmgrinfo_get_appinfo(const char *appid, uid_t uid,
                ret = _appinfo_get_applications(GLOBAL_USER, uid, locale, filter,
                                PMINFO_APPINFO_GET_ALL, list);
 
+       if (ret != PMINFO_R_OK) {
+               g_hash_table_destroy(list);
+               free(locale);
+               return ret;
+       }
+
        if (!g_hash_table_size(list)) {
                _LOGD("appinfo for [%s] is not existed for user [%d]",
                                appid, uid);
@@ -754,6 +770,7 @@ static int _pkgmgrinfo_get_appinfo(const char *appid, uid_t uid,
        info->package = strdup(info->app_info->package);
 
        /* just free list only */
+       g_hash_table_steal(list, (gconstpointer)appid);
        g_hash_table_destroy(list);
 
        *handle = info;