Fix memory leak when _XKB_RULES_NAMES can't be found
Steps to reproduce:
1. Force the branch to be taken:
diff --git a/src/bindings.c b/src/bindings.c
index fe77bc8f..caa5848c 100644
--- a/src/bindings.c
+++ b/src/bindings.c
@@ -941,7 +941,7 @@ bool load_keymap(void) {
struct xkb_keymap *new_keymap = NULL;
int32_t device_id;
- if (xkb_supported && (device_id = xkb_x11_get_core_keyboard_device_id(conn)) > -1) {
+ if (0) {
if ((new_keymap = xkb_x11_keymap_new_from_device(xkb_context, conn, device_id, 0)) == NULL) {
ELOG("xkb_x11_keymap_new_from_device failed\n");
return false;
2. Run `python2 ./xproperty.py _XKB_RULES_NAMES ''` (from
https://github.com/siemer/xproperty) in the xinitrc
3. Memory sanitizers detect memory leaks.
Note: We don't (and didn't) pass NULL in xkb_keymap_new_from_names() but
an xkb_rule_names structures with NULL fields (fill_rmlvo_from_root only
fills its argument when there are no errors) should be equivalent:
767fa86d42/NEWS (L349-L351)
> The function xkb_keymap_new_from_names() now accepts a NULL value for
the 'names' parameter, instead of failing. This is equivalent to passing
a 'struct xkb_rule_names' with all fields set to NULL.
Fixes #2535.
This commit is contained in:
parent
77bfa595df
commit
4143f3abfc
|
@ -958,10 +958,7 @@ bool load_keymap(void) {
|
||||||
.options = NULL};
|
.options = NULL};
|
||||||
if (fill_rmlvo_from_root(&names) == -1) {
|
if (fill_rmlvo_from_root(&names) == -1) {
|
||||||
ELOG("Could not get _XKB_RULES_NAMES atom from root window, falling back to defaults.\n");
|
ELOG("Could not get _XKB_RULES_NAMES atom from root window, falling back to defaults.\n");
|
||||||
if ((new_keymap = xkb_keymap_new_from_names(xkb_context, &names, 0)) == NULL) {
|
/* Using NULL for the fields of xkb_rule_names. */
|
||||||
ELOG("xkb_keymap_new_from_names(NULL) failed\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
new_keymap = xkb_keymap_new_from_names(xkb_context, &names, 0);
|
new_keymap = xkb_keymap_new_from_names(xkb_context, &names, 0);
|
||||||
free((char *)names.rules);
|
free((char *)names.rules);
|
||||||
|
@ -970,7 +967,7 @@ bool load_keymap(void) {
|
||||||
free((char *)names.variant);
|
free((char *)names.variant);
|
||||||
free((char *)names.options);
|
free((char *)names.options);
|
||||||
if (new_keymap == NULL) {
|
if (new_keymap == NULL) {
|
||||||
ELOG("xkb_keymap_new_from_names(RMLVO) failed\n");
|
ELOG("xkb_keymap_new_from_names failed\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue