input: keymap(): use a goto-label on error, to ensure we always close the keymap FD

This commit is contained in:
Daniel Eklöf 2025-10-18 08:23:53 +02:00
parent 82e75851e4
commit 5587604469
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

17
input.c
View file

@ -576,23 +576,20 @@ keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard,
/* Verify keymap is in a format we understand */
switch ((enum wl_keyboard_keymap_format)format) {
case WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP:
close(fd);
return;
goto err;
case WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1:
break;
default:
LOG_WARN("unrecognized keymap format: %u", format);
close(fd);
return;
goto err;
}
char *map_str = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
if (map_str == MAP_FAILED) {
LOG_ERRNO("failed to mmap keyboard keymap");
close(fd);
return;
goto err;
}
while (map_str[size - 1] == '\0')
@ -605,6 +602,8 @@ keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard,
}
munmap(map_str, size);
if (seat->kbd.xkb_keymap != NULL) {
seat->kbd.xkb_state = xkb_state_new(seat->kbd.xkb_keymap);
@ -685,10 +684,10 @@ keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard,
seat->kbd.key_arrow_down = xkb_keymap_key_by_name(seat->kbd.xkb_keymap, "DOWN");
}
munmap(map_str, size);
close(fd);
key_binding_load_keymap(wayl->key_binding_manager, seat);
err:
close(fd);
}
static void