imwayland: destroy objects only if it matches our manager object
authorLionel Landwerlin <llandwerlin@gmail.com>
Tue, 27 Mar 2018 18:42:43 +0000 (19:42 +0100)
committerSimon McVittie <smcv@debian.org>
Tue, 3 Apr 2018 07:41:09 +0000 (08:41 +0100)
Should fix one of the crash from #129.

Bug: https://gitlab.gnome.org/GNOME/gtk/issues/129
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=894388
Forwarded: https://gitlab.gnome.org/GNOME/gtk/merge_requests/89
Applied-upstream: no

Gbp-Pq: Name 0016-imwayland-destroy-objects-only-if-it-matches-our-man.patch

modules/input/imwayland.c

index 30d253665bcc76abff728eeb66a1eb92e8a642ba..89b2f7af1abdf5d2e7fc265755e8fb0cbb8313d7 100644 (file)
@@ -35,6 +35,7 @@ struct _GtkIMContextWaylandGlobal
 {
   struct wl_display *display;
   struct wl_registry *registry;
+  uint32_t text_input_manager_wl_id;
   struct gtk_text_input_manager *text_input_manager;
   struct gtk_text_input *text_input;
   uint32_t enter_serial;
@@ -205,8 +206,9 @@ registry_handle_global (void               *data,
 
   if (strcmp (interface, "gtk_text_input_manager") == 0)
     {
+      global->text_input_manager_wl_id = id;
       global->text_input_manager =
-        wl_registry_bind (global->registry, id,
+        wl_registry_bind (global->registry, global->text_input_manager_wl_id,
                           &gtk_text_input_manager_interface, 1);
       global->text_input =
         gtk_text_input_manager_get_text_input (global->text_input_manager,
@@ -223,11 +225,11 @@ registry_handle_global_remove (void               *data,
 {
   GtkIMContextWaylandGlobal *global = data;
 
-  gtk_text_input_destroy (global->text_input);
-  global->text_input = NULL;
+  if (id != global->text_input_manager_wl_id)
+    return;
 
-  gtk_text_input_manager_destroy (global->text_input_manager);
-  global->text_input_manager = NULL;
+  g_clear_pointer(&global->text_input, gtk_text_input_destroy);
+  g_clear_pointer(&global->text_input_manager, gtk_text_input_manager_destroy);
 }
 
 static const struct wl_registry_listener registry_listener = {