[gnome-software/1699-crash-under-gs_plugin_flatpak_find_app_by_ref] flatpak: Use cached runtime only if it had been refined



commit 14a313d0f6fc1b358afc8bac99604213a317f1de
Author: Milan Crha <mcrha redhat com>
Date:   Mon Jun 20 21:08:07 2022 +0200

    flatpak: Use cached runtime only if it had been refined
    
    The runtime can be added to the plugin cache through the appstream data,
    but it doesn't mean it is also refined when it is asked for it, thus make
    sure only runtime with necessary (and the same as expected) properties
    is returned from the cache within gs_flatpak_create_runtime()
    
    Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1699

 plugins/flatpak/gs-flatpak.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
---
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index 36833fb33..112dd06ed 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -2367,21 +2367,32 @@ gs_flatpak_create_runtime (GsFlatpak   *self,
 
        /* search in the cache */
        app_cache = gs_plugin_cache_lookup (self->plugin, gs_app_get_unique_id (app));
-       if (app_cache != NULL) {
+       if (app_cache != NULL &&
+           g_strcmp0 (gs_flatpak_app_get_ref_name (app_cache), split[0]) == 0 &&
+           g_strcmp0 (gs_flatpak_app_get_ref_arch (app_cache), split[1]) == 0 &&
+           g_strcmp0 (gs_app_get_branch (app_cache), split[2]) == 0) {
                /* since the cached runtime can have been created somewhere else
                 * (we're using a global cache), we need to make sure that a
                 * source is set */
                if (gs_app_get_source_default (app_cache) == NULL)
                        gs_app_add_source (app_cache, source);
                return g_steal_pointer (&app_cache);
+       } else {
+               g_clear_object (&app_cache);
        }
 
        /* if the app is per-user we can also use the installed system runtime */
        if (gs_app_get_scope (parent) == AS_COMPONENT_SCOPE_USER) {
                gs_app_set_scope (app, AS_COMPONENT_SCOPE_UNKNOWN);
                app_cache = gs_plugin_cache_lookup (self->plugin, gs_app_get_unique_id (app));
-               if (app_cache != NULL)
+               if (app_cache != NULL &&
+                   g_strcmp0 (gs_flatpak_app_get_ref_name (app_cache), split[0]) == 0 &&
+                   g_strcmp0 (gs_flatpak_app_get_ref_arch (app_cache), split[1]) == 0 &&
+                   g_strcmp0 (gs_app_get_branch (app_cache), split[2]) == 0) {
                        return g_steal_pointer (&app_cache);
+               } else {
+                       g_clear_object (&app_cache);
+               }
        }
 
        /* set superclassed app properties */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]