Cloudef / wlc

High-level Wayland compositor library
MIT License
330 stars 58 forks source link

dereferenced keyboard context in wlc_keymap #201

Closed joe9 closed 8 years ago

joe9 commented 8 years ago

Hello,

The keyboard context is being dereferenced here (line 88-89 of https://github.com/Cloudef/wlc/blob/401497a36ab3286d3725d7f5b8da5fdf43e44e19/src/compositor/seat/keymap.c

Is this intentional? The libxkbcommon docs mention that the context should only be dereferenced at the end.

bool
wlc_keymap(struct wlc_keymap *keymap, const struct xkb_rule_names *names, enum xkb_keymap_compile_flags flags)
{
   assert(keymap);
   memset(keymap, 0, sizeof(struct wlc_keymap));

   char *keymap_str = NULL;

   struct xkb_context *context;
   if (!(context = xkb_context_new(XKB_CONTEXT_NO_FLAGS)))
      goto context_fail;

   if (!(keymap->keymap = xkb_map_new_from_names(context, names, flags)))
      goto keymap_fail;

   xkb_context_unref(context);
   context = NULL;

   if (!(keymap_str = xkb_map_get_as_string(keymap->keymap)))
      goto string_fail;

Thanks

Cloudef commented 8 years ago

We don't actually use the context for anything, just create it and pass it to keymap. XKB keymap and context are reference counted, thus xkb_context_unref doesn't actually release the context from memory here, just decrease its reference count (otherwise we would leak).

See: https://github.com/xkbcommon/libxkbcommon/blob/3fee46a2186d597c52bc1e06ee14e32ac548b764/src/keymap-priv.c#L65