mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-10-29 05:40:12 -04:00
Merge pull request #88 from 4e554c4c/alloc_crashing
Prevent alloc errors from crashing
This commit is contained in:
commit
27c13d621d
13 changed files with 109 additions and 13 deletions
|
|
@ -39,8 +39,10 @@ static struct wlr_input_device *allocate_device(
|
|||
int vendor = libinput_device_get_id_vendor(libinput_dev);
|
||||
int product = libinput_device_get_id_product(libinput_dev);
|
||||
const char *name = libinput_device_get_name(libinput_dev);
|
||||
struct wlr_libinput_input_device *wlr_libinput_dev =
|
||||
calloc(1, sizeof(struct wlr_libinput_input_device));
|
||||
struct wlr_libinput_input_device *wlr_libinput_dev;
|
||||
if (!(wlr_libinput_dev = calloc(1, sizeof(struct wlr_libinput_input_device)))) {
|
||||
return NULL;
|
||||
}
|
||||
struct wlr_input_device *wlr_dev = &wlr_libinput_dev->wlr_input_device;
|
||||
wlr_libinput_dev->handle = libinput_dev;
|
||||
libinput_device_ref(libinput_dev);
|
||||
|
|
@ -63,36 +65,74 @@ static void handle_device_added(struct wlr_libinput_backend *backend,
|
|||
int product = libinput_device_get_id_product(libinput_dev);
|
||||
const char *name = libinput_device_get_name(libinput_dev);
|
||||
list_t *wlr_devices = list_create();
|
||||
if (!wlr_devices) {
|
||||
goto fail;
|
||||
}
|
||||
wlr_log(L_DEBUG, "Added %s [%d:%d]", name, vendor, product);
|
||||
|
||||
if (libinput_device_has_capability(libinput_dev, LIBINPUT_DEVICE_CAP_KEYBOARD)) {
|
||||
struct wlr_input_device *wlr_dev = allocate_device(backend,
|
||||
libinput_dev, wlr_devices, WLR_INPUT_DEVICE_KEYBOARD);
|
||||
if (!wlr_dev) {
|
||||
goto fail;
|
||||
}
|
||||
wlr_dev->keyboard = wlr_libinput_keyboard_create(libinput_dev);
|
||||
if (!wlr_dev->keyboard) {
|
||||
free(wlr_dev);
|
||||
goto fail;
|
||||
}
|
||||
wl_signal_emit(&backend->backend.events.input_add, wlr_dev);
|
||||
}
|
||||
if (libinput_device_has_capability(libinput_dev, LIBINPUT_DEVICE_CAP_POINTER)) {
|
||||
struct wlr_input_device *wlr_dev = allocate_device(backend,
|
||||
libinput_dev, wlr_devices, WLR_INPUT_DEVICE_POINTER);
|
||||
if (!wlr_dev) {
|
||||
goto fail;
|
||||
}
|
||||
wlr_dev->pointer = wlr_libinput_pointer_create(libinput_dev);
|
||||
if (!wlr_dev->pointer) {
|
||||
free(wlr_dev);
|
||||
goto fail;
|
||||
}
|
||||
wl_signal_emit(&backend->backend.events.input_add, wlr_dev);
|
||||
}
|
||||
if (libinput_device_has_capability(libinput_dev, LIBINPUT_DEVICE_CAP_TOUCH)) {
|
||||
struct wlr_input_device *wlr_dev = allocate_device(backend,
|
||||
libinput_dev, wlr_devices, WLR_INPUT_DEVICE_TOUCH);
|
||||
if (!wlr_dev) {
|
||||
goto fail;
|
||||
}
|
||||
wlr_dev->touch = wlr_libinput_touch_create(libinput_dev);
|
||||
if (!wlr_dev->touch) {
|
||||
free(wlr_dev);
|
||||
goto fail;
|
||||
}
|
||||
wl_signal_emit(&backend->backend.events.input_add, wlr_dev);
|
||||
}
|
||||
if (libinput_device_has_capability(libinput_dev, LIBINPUT_DEVICE_CAP_TABLET_TOOL)) {
|
||||
struct wlr_input_device *wlr_dev = allocate_device(backend,
|
||||
libinput_dev, wlr_devices, WLR_INPUT_DEVICE_TABLET_TOOL);
|
||||
if (!wlr_dev) {
|
||||
goto fail;
|
||||
}
|
||||
wlr_dev->tablet_tool = wlr_libinput_tablet_tool_create(libinput_dev);
|
||||
if (!wlr_dev->tablet_tool) {
|
||||
free(wlr_dev);
|
||||
goto fail;
|
||||
}
|
||||
wl_signal_emit(&backend->backend.events.input_add, wlr_dev);
|
||||
}
|
||||
if (libinput_device_has_capability(libinput_dev, LIBINPUT_DEVICE_CAP_TABLET_PAD)) {
|
||||
struct wlr_input_device *wlr_dev = allocate_device(backend,
|
||||
libinput_dev, wlr_devices, WLR_INPUT_DEVICE_TABLET_PAD);
|
||||
if (!wlr_dev) {
|
||||
goto fail;
|
||||
}
|
||||
wlr_dev->tablet_pad = wlr_libinput_tablet_pad_create(libinput_dev);
|
||||
if (!wlr_dev->tablet_pad) {
|
||||
free(wlr_dev);
|
||||
goto fail;
|
||||
}
|
||||
wl_signal_emit(&backend->backend.events.input_add, wlr_dev);
|
||||
}
|
||||
if (libinput_device_has_capability(libinput_dev, LIBINPUT_DEVICE_CAP_GESTURE)) {
|
||||
|
|
@ -108,6 +148,12 @@ static void handle_device_added(struct wlr_libinput_backend *backend,
|
|||
} else {
|
||||
list_free(wlr_devices);
|
||||
}
|
||||
return;
|
||||
|
||||
fail:
|
||||
wlr_log(L_ERROR, "Could not allocate new device");
|
||||
list_foreach(wlr_devices, free);
|
||||
list_free(wlr_devices);
|
||||
}
|
||||
|
||||
static void handle_device_removed(struct wlr_libinput_backend *backend,
|
||||
|
|
|
|||
|
|
@ -32,8 +32,10 @@ struct wlr_keyboard_impl impl = {
|
|||
struct wlr_keyboard *wlr_libinput_keyboard_create(
|
||||
struct libinput_device *libinput_dev) {
|
||||
assert(libinput_dev);
|
||||
struct wlr_libinput_keyboard *wlr_libinput_kb =
|
||||
calloc(1, sizeof(struct wlr_libinput_keyboard));
|
||||
struct wlr_libinput_keyboard *wlr_libinput_kb;
|
||||
if (!(wlr_libinput_kb= calloc(1, sizeof(struct wlr_libinput_keyboard)))) {
|
||||
return NULL;
|
||||
}
|
||||
wlr_libinput_kb->libinput_dev = libinput_dev;
|
||||
libinput_device_ref(libinput_dev);
|
||||
libinput_device_led_update(libinput_dev, 0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue