wayland/surface: Only call destroy func when available
authorGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Tue, 1 Oct 2019 14:54:28 +0000 (11:54 -0300)
committerGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Tue, 1 Oct 2019 14:54:28 +0000 (11:54 -0300)
When calling gdk_wayland_surface_export_handle(), if we pass
some 'user_data' but no 'destroy_func', GTK4 crashes. That's
because in xdg_exported_handle() we are unconditionally calling
destroy_func -- even when it's NULL.

Fix that by checking if there's a destroy function before calling
it.

Fixes https://gitlab.gnome.org/GNOME/gtk/issues/2179

gdk/wayland/gdksurface-wayland.c

index 0a8043b16ef77edc1abff4f1f479de4dbf1a1ff6..aed4489c7cf2c8489ad96b1f9debee647dd08ee4 100644 (file)
@@ -4063,8 +4063,11 @@ xdg_exported_handle (void                    *data,
   GdkWaylandSurface *impl = GDK_WAYLAND_SURFACE (surface);
 
   impl->exported.callback (surface, handle, impl->exported.user_data);
-  g_clear_pointer (&impl->exported.user_data,
-                   impl->exported.destroy_func);
+  if (impl->exported.destroy_func)
+    {
+      g_clear_pointer (&impl->exported.user_data,
+                       impl->exported.destroy_func);
+    }
 }
 
 static const struct zxdg_exported_v1_listener xdg_exported_listener = {