wayland/gtk-shell: Fix MetaWaylandGtkSurface leak on surface destroy

The MetaWaylandSurface corresponding to a MetaWaylandGtkSurface can be
destroyed before the MetaWaylandGtkSurface is destroyed. In its destroy
function MetaWaylandSurface however was unsetting the destructor of the
correspnding resource along with the gtk_surface1 interface
implementation. This was done to prevent further gtk_surface1 requests
on a NULLed MetaWaylandSurface, if it has been destroyed before the
MetaWaylandGtkSurface.

It would be enough to just unset the resource implementation, while
keeping the destructor to fix this leak. However the following commit
will rely on the implementation being available after the
MetaWaylandSurface has been destroyed. So instead introduce NULL checks
for all functions that can be called on the gtk_surface1 interface and
do not unset the implementation.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1307>
This commit is contained in:
Sebastian Keller 2020-06-09 04:07:52 +02:00 committed by Marge Bot
parent 893c0cd2f9
commit b41c4aec26

View File

@ -83,6 +83,9 @@ gtk_surface_set_dbus_properties (struct wl_client *client,
MetaWaylandSurface *surface = gtk_surface->surface;
MetaWindow *window;
if (!surface)
return;
window = meta_wayland_surface_get_window (surface);
if (!window)
return;
@ -104,6 +107,9 @@ gtk_surface_set_modal (struct wl_client *client,
MetaWaylandSurface *surface = gtk_surface->surface;
MetaWindow *window;
if (!surface)
return;
window = meta_wayland_surface_get_window (surface);
if (!window)
return;
@ -123,6 +129,9 @@ gtk_surface_unset_modal (struct wl_client *client,
MetaWaylandSurface *surface = gtk_surface->surface;
MetaWindow *window;
if (!surface)
return;
window = meta_wayland_surface_get_window (surface);
if (!window)
return;
@ -143,6 +152,9 @@ gtk_surface_present (struct wl_client *client,
MetaWaylandSurface *surface = gtk_surface->surface;
MetaWindow *window;
if (!surface)
return;
window = meta_wayland_surface_get_window (surface);
if (!window)
return;
@ -162,6 +174,9 @@ gtk_surface_request_focus (struct wl_client *client,
MetaStartupSequence *sequence = NULL;
MetaWindow *window;
if (!surface)
return;
window = meta_wayland_surface_get_window (surface);
if (!window)
return;
@ -204,8 +219,6 @@ static const struct gtk_surface1_interface meta_wayland_gtk_surface_interface =
static void
gtk_surface_surface_destroyed (MetaWaylandGtkSurface *gtk_surface)
{
wl_resource_set_implementation (gtk_surface->resource,
NULL, NULL, NULL);
gtk_surface->surface = NULL;
}