wlroots-hyprland/types/wlr_keyboard.c
Markus Ongyerth 935b6d871e fixes use after free caused by signal lists
A structs throughout the code use implementation specific free
functions.
When those functions are not used, they simply call free() on their
data, but this leaves around wl_signals linked into listeners.
When those listeners try to remove themself from the list, they write
into the now free memory.

This commit adds calls to remove the signals from those lists, so the
listeners can safely call wl_list_remove
2017-09-08 16:02:26 +02:00

26 lines
635 B
C

#include <stdlib.h>
#include <string.h>
#include <wayland-server.h>
#include <wlr/types/wlr_keyboard.h>
#include <wlr/interfaces/wlr_keyboard.h>
void wlr_keyboard_init(struct wlr_keyboard *kb,
struct wlr_keyboard_impl *impl) {
kb->impl = impl;
wl_signal_init(&kb->events.key);
}
void wlr_keyboard_destroy(struct wlr_keyboard *kb) {
if (kb && kb->impl && kb->impl->destroy) {
kb->impl->destroy(kb);
} else {
wl_list_remove(&kb->events.key.listener_list);
free(kb);
}
}
void wlr_keyboard_led_update(struct wlr_keyboard *kb, uint32_t leds) {
if (kb->impl && kb->impl->led_update) {
kb->impl->led_update(kb, leds);
}
}