renderer/native: Clear old KMS updates on views rebuild

If there are any pending updates, for example if we painted one of
multiple monitors but without having posted the update due to waiting
for another monitor to be painted, but before we paint all of them and
post the update, another hotplug event happens, we'd have stale pending
KMS update. When that update eventually would be processed, we'd try to
apply out-of-date updates which may contain freed memory.

Fix this by discarding any update when we're rebuilding the views. We
can be sure not to need any of the old updates since we're rebuilding
the whole content anyway.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/1928
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2216>
This commit is contained in:
Jonas Ådahl 2022-01-07 22:27:51 +01:00 committed by Marge Bot
parent af08847126
commit 8e91c6295d
3 changed files with 9 additions and 0 deletions

View File

@ -181,6 +181,12 @@ struct _MetaKms
G_DEFINE_TYPE (MetaKms, meta_kms, G_TYPE_OBJECT) G_DEFINE_TYPE (MetaKms, meta_kms, G_TYPE_OBJECT)
void
meta_kms_discard_pending_updates (MetaKms *kms)
{
g_clear_list (&kms->pending_updates, (GDestroyNotify) meta_kms_update_free);
}
static void static void
meta_kms_add_pending_update (MetaKms *kms, meta_kms_add_pending_update (MetaKms *kms,
MetaKmsUpdate *update) MetaKmsUpdate *update)

View File

@ -41,6 +41,8 @@ typedef enum _MetaKmsUpdateFlag
#define META_TYPE_KMS (meta_kms_get_type ()) #define META_TYPE_KMS (meta_kms_get_type ())
G_DECLARE_FINAL_TYPE (MetaKms, meta_kms, META, KMS, GObject) G_DECLARE_FINAL_TYPE (MetaKms, meta_kms, META, KMS, GObject)
void meta_kms_discard_pending_updates (MetaKms *kms);
MetaKmsUpdate * meta_kms_ensure_pending_update (MetaKms *kms, MetaKmsUpdate * meta_kms_ensure_pending_update (MetaKms *kms,
MetaKmsDevice *device); MetaKmsDevice *device);

View File

@ -1391,6 +1391,7 @@ meta_renderer_native_rebuild_views (MetaRenderer *renderer)
META_RENDERER_CLASS (meta_renderer_native_parent_class); META_RENDERER_CLASS (meta_renderer_native_parent_class);
meta_kms_discard_pending_page_flips (kms); meta_kms_discard_pending_page_flips (kms);
meta_kms_discard_pending_updates (kms);
keep_current_onscreens_alive (renderer); keep_current_onscreens_alive (renderer);