From bda2d6d1ac764c5d41badf45c01e05730d3caa1f Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Thu, 14 Aug 2014 17:23:20 -0400 Subject: [PATCH] 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 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/backends/x11/meta-backend-x11.c b/src/backends/x11/meta-backend-x11.c index 2d420cb05..14ba28c8b 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