fix memory leaks

This commit is contained in:
Tony Crisci 2017-12-18 14:53:24 -05:00
parent 20327d82cb
commit c838679393
2 changed files with 7 additions and 1 deletions

View File

@ -364,6 +364,7 @@ struct roots_keyboard *roots_keyboard_create(struct wlr_input_device *device,
} }
wlr_keyboard_set_keymap(device->keyboard, keymap); wlr_keyboard_set_keymap(device->keyboard, keymap);
xkb_keymap_unref(keymap);
xkb_context_unref(context); xkb_context_unref(context);
int repeat_rate = (config->repeat_rate > 0) ? config->repeat_rate : 25; int repeat_rate = (config->repeat_rate > 0) ? config->repeat_rate : 25;

View File

@ -118,7 +118,7 @@ void wlr_keyboard_destroy(struct wlr_keyboard *kb) {
wl_list_remove(&kb->events.key.listener_list); wl_list_remove(&kb->events.key.listener_list);
} }
xkb_state_unref(kb->xkb_state); xkb_state_unref(kb->xkb_state);
xkb_map_unref(kb->keymap); xkb_keymap_unref(kb->keymap);
close(kb->keymap_fd); close(kb->keymap_fd);
free(kb); free(kb);
} }
@ -136,6 +136,11 @@ void wlr_keyboard_set_keymap(struct wlr_keyboard *kb,
} }
xkb_keymap_ref(keymap); xkb_keymap_ref(keymap);
kb->keymap = keymap; kb->keymap = keymap;
if (kb->xkb_state) {
xkb_state_unref(kb->xkb_state);
}
kb->xkb_state = xkb_state_new(kb->keymap); kb->xkb_state = xkb_state_new(kb->keymap);
if (kb->xkb_state == NULL) { if (kb->xkb_state == NULL) {
wlr_log(L_ERROR, "Failed to create XKB state"); wlr_log(L_ERROR, "Failed to create XKB state");