e_keyrouter: fix crash issue in case event handler mutex is not initialized 40/310640/2
authorJihoon Kim <jihoon48.kim@samsung.com>
Fri, 3 May 2024 08:05:48 +0000 (17:05 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Tue, 7 May 2024 01:42:29 +0000 (10:42 +0900)
Change-Id: Ie89e3f45f70c81b9d7b6c29c81b5a5ce5f521fcc
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
src/bin/e_keyrouter.c
src/bin/e_keyrouter_private.h
src/bin/e_main.c

index d4c1582..370d10f 100644 (file)
@@ -5,6 +5,8 @@
 
 #include <glib.h>
 
+static GMutex event_handler_mutex;
+
 static int _e_keyrouter_intercept_hooks_delete = 0;
 static int _e_keyrouter_intercept_hooks_walking = 0;
 
@@ -361,7 +363,7 @@ _e_keyrouter_init_handlers(void)
         input_event_source = e_input_event_source_get();
         if (input_event_source)
           {
-             g_mutex_lock(&krt->event_handler_mutex);
+             g_mutex_lock(&event_handler_mutex);
 
              if (!krt->_key_down_handler)
                krt->_key_down_handler = e_input_event_handler_add(input_event_source, ECORE_EVENT_KEY_DOWN, _e_keyrouter_cb_key_down, NULL);
@@ -369,7 +371,7 @@ _e_keyrouter_init_handlers(void)
              if (!krt->_key_up_handler)
                krt->_key_up_handler = e_input_event_handler_add(input_event_source, ECORE_EVENT_KEY_UP, _e_keyrouter_cb_key_up, NULL);
 
-             g_mutex_unlock(&krt->event_handler_mutex);
+             g_mutex_unlock(&event_handler_mutex);
           }
      }
 
@@ -393,7 +395,7 @@ _e_keyrouter_deinit_handlers(void)
         input_event_source = e_input_event_source_get();
         if (input_event_source)
           {
-             g_mutex_clear(&krt->event_handler_mutex);
+             g_mutex_clear(&event_handler_mutex);
 
              if (krt->_key_down_handler)
                e_input_event_handler_del(input_event_source, krt->_key_down_handler);
@@ -650,7 +652,7 @@ e_keyrouter_input_handler_add(void)
          return;
       }
 
-   g_mutex_lock(&krt->event_handler_mutex);
+   g_mutex_lock(&event_handler_mutex);
 
    if (!krt->_key_down_handler)
      krt->_key_down_handler = e_input_event_handler_add(input_event_source, ECORE_EVENT_KEY_DOWN, _e_keyrouter_cb_key_down, NULL);
@@ -658,7 +660,14 @@ e_keyrouter_input_handler_add(void)
    if (!krt->_key_up_handler)
      krt->_key_up_handler = e_input_event_handler_add(input_event_source, ECORE_EVENT_KEY_UP, _e_keyrouter_cb_key_up, NULL);
 
-   g_mutex_unlock(&krt->event_handler_mutex);
+   g_mutex_unlock(&event_handler_mutex);
+}
+
+EINTERN void
+e_keyrouter_mutex_init(void)
+{
+   if (e_input_thread_mode_get())
+     g_mutex_init(&event_handler_mutex);
 }
 
 EINTERN int
@@ -678,9 +687,6 @@ e_keyrouter_init(void)
    krt = E_NEW(E_Keyrouter, 1);
    EINA_SAFETY_ON_NULL_GOTO(krt, err);
 
-   if (e_input_thread_mode_get())
-     g_mutex_init(&krt->event_handler_mutex);
-
    g_rec_mutex_init(&krt->grab_key_mutex);
 
    kconfig = E_NEW(E_Keyrouter_Config_Data, 1);
index ed27d79..da0e497 100644 (file)
@@ -89,7 +89,6 @@ struct _E_Keyrouter
 
    E_Input_Event_Handler *_key_down_handler;
    E_Input_Event_Handler *_key_up_handler;
-   GMutex event_handler_mutex;
    GRecMutex grab_key_mutex;
 };
 
@@ -139,3 +138,4 @@ Eina_Bool e_keyrouter_wl_key_send(Ecore_Event_Key *ev, E_Device *dev, Eina_Bool
 void e_keyrouter_keycancel_send(struct wl_client *client, struct wl_resource *surface, unsigned int key);
 void e_keyrouter_wl_event_surface_send(struct wl_resource *surface, int key, int mode);
 
+void e_keyrouter_mutex_init(void);
\ No newline at end of file
index 6dab8d8..fff04e6 100644 (file)
@@ -5,6 +5,7 @@
 #ifdef HAVE_SYSTEMD
 # include <systemd/sd-daemon.h>
 #endif
+#include "e_keyrouter_private.h"
 
 #define MAX_LEVEL 80
 
@@ -583,6 +584,7 @@ main(int argc, char **argv)
    e_zone_init();
    e_desk_init();
    e_magnifier_init();
+   e_keyrouter_mutex_init();
 
    TRACE_DS_BEGIN(MAIN:WAIT /dev/dri/card0);
    if (e_config->sleep_for_dri)