For error handling code, it's nice to be able to pass NULL to these
function without worrying about segfaults ensuing. free() sets the
precedent here.
Also document this fact.
Signed-off-by: Ran Benita <ran234@gmail.com>
XKB_EXPORT void
xkb_context_unref(struct xkb_context *ctx)
{
- if (--ctx->refcnt > 0)
+ if (!ctx || --ctx->refcnt > 0)
return;
xkb_context_include_path_clear(ctx);
XKB_EXPORT void
xkb_state_unref(struct xkb_state *state)
{
- if (--state->refcnt > 0)
+ if (!state || --state->refcnt > 0)
return;
xkb_keymap_unref(state->keymap);
assert(context);
+ /* Make sure these are allowed. */
+ xkb_context_unref(NULL);
+ xkb_keymap_unref(NULL);
+ xkb_state_unref(NULL);
+
keymap = test_compile_rules(context, "evdev", "pc104", "us,ru", NULL, "grp:menu_toggle");
assert(keymap);
/**
* Release a reference on a context, and possibly free it.
*
+ * @param context The context. If it is NULL, this function does nothing.
+ *
* @memberof xkb_context
*/
void
/**
* Release a reference on a keymap, and possibly free it.
*
+ * @param keymap The keymap. If it is NULL, this function does nothing.
+ *
* @memberof xkb_keymap
*/
void
/**
* Release a reference on a keybaord state object, and possibly free it.
*
+ * @param state The state. If it is NULL, this function does nothing.
+ *
* @memberof xkb_state
*/
void