Skip to content

Couple of fixes for GtkDisplay open/close

Olivier Fourdan requested to merge ofourdan/gtk:display-woes into gtk-3-24

As part of gnome-shell!941 (merged) to fix gnome-shell#2139 (closed) and be able to run gnome-shell-perf-helper independently of gnome-shell even on Wayland (where gnome-shell is the display server), I noticed that opening and closing GdkDisplay several times could lead to a crash.

This is because, since commit 360a3c16, GTK caches the settings per display in a static GArray, keeping a reference to the GdkDisplay`.

However, when closing the display, the corresponding entry is not removed from the cache in GtkSettings.

So when reopening again a GdkDisplay, if the new address matches one of the previously closed display, the cache will return the existing GtkSettings from the cache, which still holds a reference to the old GdkScreen which was freed along the GdkDisplay.

To avoid the issue, make sure to remove the GdkDisplay and corresponding GdkSettings when closing the GdkDisplay.

Also, care must be taken not to recreate the GdkSettings and re-add the GdkDisplay to the cache once the display is closed, and make sure callers of gtk_settings_get_for_display() can deal with a returned value being NULL if the display is closed.

This MR is to fix this crash and also fix a warning caused by a wrong type casting in gdk_window_impl_wayland_finalize()

Edited by Olivier Fourdan

Merge request reports