mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-26 14:45:58 +01:00
wlr_keyboard_group: fix mem leak in refresh_state
This fixes a memory leak the refresh_state function for wlr_keyboard_group. The event struct was being dynamically allocated and never free'd. This changes it to a static allocation.
This commit is contained in:
parent
471f9a3f6a
commit
e0e5a167ed
1 changed files with 7 additions and 11 deletions
|
@ -200,19 +200,15 @@ static void handle_keyboard_repeat_info(struct wl_listener *listener,
|
||||||
static void refresh_state(struct keyboard_group_device *device,
|
static void refresh_state(struct keyboard_group_device *device,
|
||||||
enum wlr_key_state state) {
|
enum wlr_key_state state) {
|
||||||
for (size_t i = 0; i < device->keyboard->num_keycodes; i++) {
|
for (size_t i = 0; i < device->keyboard->num_keycodes; i++) {
|
||||||
struct wlr_event_keyboard_key *event =
|
|
||||||
calloc(1, sizeof(struct wlr_event_keyboard_key));
|
|
||||||
if (!event) {
|
|
||||||
wlr_log(WLR_ERROR, "Failed to allocate wlr_event_keyboard_key");
|
|
||||||
continue; // TODO: Handle corrupt state somehow
|
|
||||||
}
|
|
||||||
struct timespec now;
|
struct timespec now;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||||
event->time_msec = (int64_t)now.tv_sec * 1000 + now.tv_nsec / 1000000;
|
struct wlr_event_keyboard_key event = {
|
||||||
event->keycode = device->keyboard->keycodes[i];
|
.time_msec = (int64_t)now.tv_sec * 1000 + now.tv_nsec / 1000000,
|
||||||
event->update_state = true;
|
.keycode = device->keyboard->keycodes[i],
|
||||||
event->state = state;
|
.update_state = true,
|
||||||
handle_keyboard_key(&device->key, event);
|
.state = state
|
||||||
|
};
|
||||||
|
handle_keyboard_key(&device->key, &event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue