Fix static analyzer issues
[platform/core/appfw/pkgmgr-info.git] / src / pkgmgrinfo_pkginfo.c
index 43f2d87..2daa84e 100644 (file)
@@ -641,13 +641,23 @@ static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid,
                if (ret != PMINFO_R_OK) {
                        _LOGE("Failed to create filter");
                        g_hash_table_destroy(list);
+                       free(locale);
                        return PMINFO_R_ERROR;
                }
        }
 
-       if (__check_disable_filter_exist(tmp_filter) == false)
-               pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter,
+       if (__check_disable_filter_exist(tmp_filter) == false) {
+               ret = pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter,
                                PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
+               if (ret != PMINFO_R_OK) {
+                       _LOGE("Failed to add filter");
+                       g_hash_table_destroy(list);
+                       free(locale);
+                       if (filter == NULL)
+                               pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
+                       return PMINFO_R_ERROR;
+               }
+       }
 
        ret = _pkginfo_get_packages(uid, locale, tmp_filter,
                        flag | PMINFO_PKGINFO_GET_BASICINFO, list);
@@ -699,7 +709,8 @@ static int _pkgmgrinfo_get_pkginfo(const char *pkgid, 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_packages);
        if (list == NULL) {
                free(locale);
                return PMINFO_R_ERROR;
@@ -738,6 +749,7 @@ static int _pkgmgrinfo_get_pkginfo(const char *pkgid, uid_t uid,
        info->locale = locale;
 
        /* just free list only */
+       g_hash_table_steal(list, (gconstpointer)pkgid);
        g_hash_table_destroy(list);
 
        *handle = info;
@@ -826,7 +838,8 @@ API int pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(const char *pkgid,
                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_packages);
        if (list == NULL) {
                pkgmgrinfo_pkginfo_filter_destroy(filter);
                free(locale);
@@ -867,6 +880,7 @@ API int pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(const char *pkgid,
        info->locale = locale;
 
        /* just free list only */
+       g_hash_table_steal(list, (gconstpointer)pkgid);
        g_hash_table_destroy(list);
 
        *handle = info;