aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominique Martinet <asmadeus@codewreck.org>2018-06-30 10:41:10 +0900
committerDominique Martinet <asmadeus@codewreck.org>2018-06-30 11:38:21 +0900
commitefef54ccf56b298e935b8707c6808e7f4eebd030 (patch)
tree09ef8b2734713274d528c25d540dbe980efba254
parent266898ca1f1eeabaaff3f951a17e612147153ce5 (diff)
wlr_keyboard: fix mmap leak + logic on close for keymap_fd
mmap leak found through static analysis
-rw-r--r--types/wlr_keyboard.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c
index 0f0cb1cf..3afbe517 100644
--- a/types/wlr_keyboard.c
+++ b/types/wlr_keyboard.c
@@ -144,6 +144,7 @@ void wlr_keyboard_init(struct wlr_keyboard *kb,
wl_signal_init(&kb->events.modifiers);
wl_signal_init(&kb->events.keymap);
wl_signal_init(&kb->events.repeat_info);
+ kb->keymap_fd = -1;
// Sane defaults
kb->repeat_info.rate = 25;
@@ -156,7 +157,9 @@ void wlr_keyboard_destroy(struct wlr_keyboard *kb) {
}
xkb_state_unref(kb->xkb_state);
xkb_keymap_unref(kb->keymap);
- close(kb->keymap_fd);
+ if (kb->keymap_fd >= 0) {
+ close(kb->keymap_fd);
+ }
if (kb->impl && kb->impl->destroy) {
kb->impl->destroy(kb);
} else {
@@ -212,7 +215,7 @@ void wlr_keyboard_set_keymap(struct wlr_keyboard *kb,
keymap_str = xkb_keymap_get_as_string(kb->keymap,
XKB_KEYMAP_FORMAT_TEXT_V1);
kb->keymap_size = strlen(keymap_str) + 1;
- if (kb->keymap_fd) {
+ if (kb->keymap_fd >= 0) {
close(kb->keymap_fd);
}
kb->keymap_fd = os_create_anonymous_file(kb->keymap_size);
@@ -228,6 +231,7 @@ void wlr_keyboard_set_keymap(struct wlr_keyboard *kb,
}
strcpy(ptr, keymap_str);
free(keymap_str);
+ munmap(ptr, kb->keymap_size);
for (size_t i = 0; i < kb->num_keycodes; ++i) {
xkb_keycode_t keycode = kb->keycodes[i] + 8;
@@ -244,7 +248,10 @@ err:
kb->xkb_state = NULL;
xkb_keymap_unref(keymap);
kb->keymap = NULL;
- close(kb->keymap_fd);
+ if (kb->keymap_fd >= 0) {
+ close(kb->keymap_fd);
+ kb->keymap_fd = -1;
+ }
free(keymap_str);
}