wayland-input : moved the xkb_state_new location and added unref it to resolve resour... 77/264477/1
authordyamy-lee <dyamy.lee@samsung.com>
Thu, 23 Sep 2021 00:34:16 +0000 (09:34 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Thu, 23 Sep 2021 02:27:10 +0000 (11:27 +0900)
Change-Id: I5edb9f4e1a487f60e66d61c515c420122c44cf14

src/modules/modality_keyboard/wayland-input.c

index f2637cb979be3a5194d3d0ceecf2c1b178065351..401c647826f804d75e7209bae80aaea3af86f658 100644 (file)
@@ -44,6 +44,7 @@ struct tizen_keyrouter *tz_keyrouter = NULL;
 
 struct xkb_context *xkb_context;
 struct xkb_keymap *keymap;
+struct xkb_state *_xkb_state = NULL;
 
 Ecore_Fd_Handler *fd_hdl;
 
@@ -218,6 +219,11 @@ keyboard_keymap(void *data, struct wl_keyboard *keyboard, unsigned int format, i
                        xkb_keymap_unref(keymap);
                        keymap = NULL;
                }
+               if(_xkb_state)
+               {
+                       xkb_state_unref(_xkb_state);
+                       _xkb_state = NULL;
+               }
                keymap = xkb_map_new_from_string(xkb_context, map, XKB_KEYMAP_FORMAT_TEXT_V1, 0);
                if(!keymap) {
                        LOGE("... Failed to get keymap from fd(%d)\n", fd);
@@ -228,6 +234,16 @@ keyboard_keymap(void *data, struct wl_keyboard *keyboard, unsigned int format, i
 
                munmap(map, size);
                close(fd);
+
+               _xkb_state = xkb_state_new(keymap);
+               if(!_xkb_state)
+               {
+                       LOGE("failed to allocate xkb state\n");
+                       xkb_keymap_unref(keymap);
+                       keymap = NULL;
+                       return;
+               }
+
                has_keymap = 1;
        }
 
@@ -272,12 +288,10 @@ static void
 _input_add_key_event(unsigned int keycode, unsigned int state, unsigned int timestamp)
 {
        char key[256] = {0, };
-       struct xkb_state *_xkb_state = NULL;
        xkb_keysym_t sym = XKB_KEY_NoSymbol;
        uint32_t nsyms;
        const xkb_keysym_t *syms;
 
-       _xkb_state = xkb_state_new(keymap);
        nsyms = xkb_key_get_syms(_xkb_state, keycode, &syms);
        if(nsyms == 1) sym = syms[0];
 
@@ -427,11 +441,16 @@ int _xkb_context_init(void)
 
 void _xkb_context_shutdown(void)
 {
-       if(!xkb_context)
-               return;
-
-       xkb_context_unref(xkb_context);
-       xkb_context = NULL;
+       if(xkb_context)
+       {
+               xkb_context_unref(xkb_context);
+               xkb_context = NULL;
+       }
+       if(_xkb_state)
+       {
+               xkb_state_unref(_xkb_state);
+               _xkb_state = NULL;
+       }
 }
 
 static void