[gtk] imwayland: destroy objects only if it matches our manager object



commit faceaec20ae3e9de9d02d31ed850919eddbb6f85
Author: Lionel Landwerlin <llandwerlin gmail com>
Date:   Tue Mar 27 19:42:43 2018 +0100

    imwayland: destroy objects only if it matches our manager object
    
    Should fix one of the crash from #129.

 gtk/gtkimcontextwayland.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtkimcontextwayland.c b/gtk/gtkimcontextwayland.c
index 5bb7ecd04d..db2a6a6053 100644
--- a/gtk/gtkimcontextwayland.c
+++ b/gtk/gtkimcontextwayland.c
@@ -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;
@@ -192,8 +193,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,
@@ -210,11 +212,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 = {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]