Fix invalid memory access issue 04/90204/3
authorJihoon Kim <jihoon48.kim@samsung.com>
Thu, 29 Sep 2016 04:10:43 +0000 (13:10 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Thu, 29 Sep 2016 04:39:56 +0000 (13:39 +0900)
g_text_input could not be initialized if text_input->input_methods is NULL in _e_text_input_cb_destroy().
It makes invalid memory access.

Change-Id: I2fd821941ccec176f1b91dddf8eff1bc76e9f059
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
src/e_mod_main.c

index c86d788..da09bd0 100644 (file)
@@ -399,8 +399,17 @@ _e_text_input_method_context_grab_set(E_Input_Method_Context *context, Eina_Bool
 
         e_comp_ungrab_input(0, 1);
 
-        if (context->kbd.keymap) xkb_map_unref(context->kbd.keymap);
-        if (context->kbd.state) xkb_state_unref(context->kbd.state);
+        if (context->kbd.keymap)
+          {
+             xkb_map_unref(context->kbd.keymap);
+             context->kbd.keymap = NULL;
+          }
+
+        if (context->kbd.state)
+          {
+             xkb_state_unref(context->kbd.state);
+             context->kbd.state = NULL;
+          }
      }
 }
 #endif
@@ -1093,8 +1102,6 @@ err:
 static void
 _e_text_input_cb_deactivate(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, struct wl_resource *seat)
 {
-   g_text_input = NULL;
-   g_client = NULL;
    E_Text_Input *text_input = wl_resource_get_user_data(resource);
    E_Input_Method *input_method = NULL;
 
@@ -1106,6 +1113,12 @@ _e_text_input_cb_deactivate(struct wl_client *client EINA_UNUSED, struct wl_reso
         return;
      }
 
+   if (text_input == g_text_input)
+     {
+        g_text_input = NULL;
+        g_client = NULL;
+     }
+
    /* FIXME: should get input_method object from seat. */
    if (g_input_method && g_input_method->resource)
      input_method = wl_resource_get_user_data(g_input_method->resource);
@@ -1650,19 +1663,20 @@ _e_text_input_cb_destroy(struct wl_resource *resource)
         return;
      }
 
-   EINA_LIST_FREE(text_input->input_methods, input_method)
+   if (g_text_input == text_input)
      {
-        if (g_text_input == text_input)
+        if (text_input->input_panel_visibile)
           {
-              if (text_input->input_panel_visibile)
-                {
-                   if (g_client)
-                     _input_panel_hide(g_client, resource, EINA_TRUE);
-                }
-
-             g_text_input = NULL;
+             if (g_client)
+               _input_panel_hide(g_client, resource, EINA_TRUE);
           }
 
+        g_text_input = NULL;
+        g_client = NULL;
+     }
+
+   EINA_LIST_FREE(text_input->input_methods, input_method)
+     {
         _e_text_input_deactivate(text_input, input_method);
      }