Fix a issue of static analysis
[platform/core/appfw/pkgmgr-info.git] / src / pkgmgrinfo_pkginfo.c
index ea64f4b..b5cac35 100644 (file)
@@ -86,6 +86,16 @@ static void __destroy_each_node(gpointer data, gpointer user_data)
        node = NULL;
 }
 
+static void __destroy_metadata_node(gpointer data)
+{
+       pkgmgrinfo_metadata_node_x *node = (pkgmgrinfo_metadata_node_x *)data;
+       if (node->key)
+               free(node->key);
+       if (node->value)
+               free(node->value);
+       free(node);
+}
+
 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
 {
        ret_if(data == NULL);
@@ -232,19 +242,19 @@ static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
        if (filter == NULL)
                return PMINFO_R_OK;
 
-       len += strlen(" WHERE 1=1 ");
        strncat(buf, " WHERE 1=1 ", MAX_QUERY_LEN - len - 1);
+       len += strlen(" WHERE 1=1 ");
        for (list = filter->list; list; list = list->next) {
                joined |= __get_filter_condition(list->data, uid, &condition,
                                bind_params);
                if (condition == NULL)
                        continue;
 
-               len += strlen(" AND ");
                strncat(buf, " AND ", MAX_QUERY_LEN - len - 1);
+               len += strlen(" AND ");
 
-               len += strlen(condition);
                strncat(buf, condition, sizeof(buf) - len - 1);
+               len += strlen(condition);
                free(condition);
                condition = NULL;
        }
@@ -366,7 +376,7 @@ static int _pkginfo_get_packages(uid_t uid, const char *locale,
        author_x *author = NULL;
        GList *bind_params = NULL;
        sqlite3 *db;
-       sqlite3_stmt *stmt;
+       sqlite3_stmt *stmt = NULL;
        pkgmgrinfo_filter_x *tmp_filter = NULL;
        bool is_check_storage = true;
 
@@ -560,7 +570,8 @@ catch:
 
        g_list_free_full(bind_params, free);
        sqlite3_close_v2(db);
-       sqlite3_finalize(stmt);
+       if (stmt)
+               sqlite3_finalize(stmt);
 
        return ret;
 }
@@ -1087,6 +1098,24 @@ API int pkgmgrinfo_pkginfo_get_zip_mount_file(pkgmgrinfo_pkginfo_h handle, char
        return PMINFO_R_OK;
 }
 
+API int pkgmgrinfo_pkginfo_get_external_image_path(pkgmgrinfo_pkginfo_h handle, char **ext_image_path)
+{
+       pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(ext_image_path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
+
+       if (info->pkg_info == NULL)
+               return PMINFO_R_ERROR;
+
+       if (info->pkg_info->external_path == NULL)
+               return PMINFO_R_ENOENT;
+
+       *ext_image_path = (char *)info->pkg_info->external_path;
+
+       return PMINFO_R_OK;
+}
+
 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
 {
        char *val;
@@ -1641,6 +1670,8 @@ API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
                g_slist_free(filter->list);
        }
 
+       g_slist_free_full(filter->list_metadata, __destroy_metadata_node);
+
        free(filter);
 
        return PMINFO_R_OK;