Merge pull request #3192 from Exagone313/next

translate_keysyms: fix potential memory leak
This commit is contained in:
Orestis 2018-03-29 12:16:12 +03:00 committed by GitHub
commit 6dfa348960
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 24 deletions

View File

@ -431,31 +431,20 @@ static void add_keycode_if_matches(struct xkb_keymap *keymap, xkb_keycode_t key,
* *
*/ */
void translate_keysyms(void) { void translate_keysyms(void) {
struct xkb_state *dummy_state = xkb_state_new(xkb_keymap); struct xkb_state *dummy_state = NULL;
if (dummy_state == NULL) { struct xkb_state *dummy_state_no_shift = NULL;
ELOG("Could not create XKB state, cannot translate keysyms.\n"); struct xkb_state *dummy_state_numlock = NULL;
return; struct xkb_state *dummy_state_numlock_no_shift = NULL;
}
struct xkb_state *dummy_state_no_shift = xkb_state_new(xkb_keymap);
if (dummy_state_no_shift == NULL) {
ELOG("Could not create XKB state, cannot translate keysyms.\n");
return;
}
struct xkb_state *dummy_state_numlock = xkb_state_new(xkb_keymap);
if (dummy_state_numlock == NULL) {
ELOG("Could not create XKB state, cannot translate keysyms.\n");
return;
}
struct xkb_state *dummy_state_numlock_no_shift = xkb_state_new(xkb_keymap);
if (dummy_state_numlock_no_shift == NULL) {
ELOG("Could not create XKB state, cannot translate keysyms.\n");
return;
}
bool has_errors = false; bool has_errors = false;
if ((dummy_state = xkb_state_new(xkb_keymap)) == NULL ||
(dummy_state_no_shift = xkb_state_new(xkb_keymap)) == NULL ||
(dummy_state_numlock = xkb_state_new(xkb_keymap)) == NULL ||
(dummy_state_numlock_no_shift = xkb_state_new(xkb_keymap)) == NULL) {
ELOG("Could not create XKB state, cannot translate keysyms.\n");
goto out;
}
Binding *bind; Binding *bind;
TAILQ_FOREACH(bind, bindings, bindings) { TAILQ_FOREACH(bind, bindings, bindings) {
#define ADD_TRANSLATED_KEY(code, mods) \ #define ADD_TRANSLATED_KEY(code, mods) \
@ -620,6 +609,7 @@ void translate_keysyms(void) {
#undef ADD_TRANSLATED_KEY #undef ADD_TRANSLATED_KEY
} }
out:
xkb_state_unref(dummy_state); xkb_state_unref(dummy_state);
xkb_state_unref(dummy_state_no_shift); xkb_state_unref(dummy_state_no_shift);
xkb_state_unref(dummy_state_numlock); xkb_state_unref(dummy_state_numlock);