[mutter] backend-x11: Don't leak the keymap



commit bda2d6d1ac764c5d41badf45c01e05730d3caa1f
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Thu Aug 14 17:23:20 2014 -0400

    backend-x11: Don't leak the keymap
    
    meta_backend_get_keymap is supposed to return a static keymap, not a new
    one every time. Cache it internally. We don't update it when the keymap
    changes on the server, but we'll do this soon.

 src/backends/x11/meta-backend-x11.c |   21 ++++++++++++---------
 1 files changed, 12 insertions(+), 9 deletions(-)
---
diff --git a/src/backends/x11/meta-backend-x11.c b/src/backends/x11/meta-backend-x11.c
index 2d420cb..14ba28c 100644
--- a/src/backends/x11/meta-backend-x11.c
+++ b/src/backends/x11/meta-backend-x11.c
@@ -63,6 +63,8 @@ struct _MetaBackendX11Private
 
   uint8_t xkb_event_base;
   uint8_t xkb_error_base;
+
+  struct xkb_keymap *keymap;
 };
 typedef struct _MetaBackendX11Private MetaBackendX11Private;
 
@@ -569,17 +571,18 @@ meta_backend_x11_get_keymap (MetaBackend *backend)
 {
   MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
   MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
-  struct xkb_keymap *keymap;
-  struct xkb_context *context;
 
-  context = xkb_context_new (XKB_CONTEXT_NO_FLAGS);
-  keymap = xkb_x11_keymap_new_from_device (context,
-                                           priv->xcb,
-                                           xkb_x11_get_core_keyboard_device_id (priv->xcb),
-                                           XKB_KEYMAP_COMPILE_NO_FLAGS);
-  xkb_context_unref (context);
+  if (priv->keymap == NULL)
+    {
+      struct xkb_context *context = xkb_context_new (XKB_CONTEXT_NO_FLAGS);
+      priv->keymap = xkb_x11_keymap_new_from_device (context,
+                                                     priv->xcb,
+                                                     xkb_x11_get_core_keyboard_device_id (priv->xcb),
+                                                     XKB_KEYMAP_COMPILE_NO_FLAGS);
+      xkb_context_unref (context);
+    }
 
-  return keymap;
+  return priv->keymap;
 }
 
 static void


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