diff options
author | Mykola Orliuk <virkony@gmail.com> | 2020-10-18 19:12:01 +0200 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2020-10-18 21:25:25 +0200 |
commit | 41bf1c6871a2bf9dc91863b9c5b8369ccaaffc61 (patch) | |
tree | a57d8e487fec70e710d5e51990f0bd54f993c125 | |
parent | 36395e5b1c4107d6945213e0c06eaa58d885f97c (diff) |
backend/wayland: add error flow in create_wl_seat
-rw-r--r-- | backend/wayland/backend.c | 4 | ||||
-rw-r--r-- | backend/wayland/seat.c | 7 | ||||
-rw-r--r-- | include/backend/wayland.h | 2 |
3 files changed, 10 insertions, 3 deletions
diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index 2059b726..459baaa6 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -105,7 +105,9 @@ static void registry_global(void *data, struct wl_registry *registry, } else if (strcmp(iface, wl_seat_interface.name) == 0) { struct wl_seat *wl_seat = wl_registry_bind(registry, name, &wl_seat_interface, 5); - create_wl_seat(wl_seat, wl); + if (!create_wl_seat(wl_seat, wl)) { + wl_seat_destroy(wl_seat); + } } else if (strcmp(iface, xdg_wm_base_interface.name) == 0) { wl->xdg_wm_base = wl_registry_bind(registry, name, &xdg_wm_base_interface, 1); diff --git a/backend/wayland/seat.c b/backend/wayland/seat.c index f20619d5..10a224a1 100644 --- a/backend/wayland/seat.c +++ b/backend/wayland/seat.c @@ -372,12 +372,17 @@ static struct wlr_wl_input_device *get_wl_input_device_from_input_device( return (struct wlr_wl_input_device *)wlr_dev; } -void create_wl_seat(struct wl_seat *wl_seat, struct wlr_wl_backend *wl) { +bool create_wl_seat(struct wl_seat *wl_seat, struct wlr_wl_backend *wl) { assert(!wl->seat); // only one seat supported at the moment struct wlr_wl_seat *seat = calloc(1, sizeof(struct wlr_wl_seat)); + if (!seat) { + wlr_log_errno(WLR_ERROR, "Allocation failed"); + return false; + } seat->wl_seat = wl_seat; wl->seat = seat; wl_seat_add_listener(wl_seat, &seat_listener, wl); + return true; } void destroy_wl_seats(struct wlr_wl_backend *wl) { diff --git a/include/backend/wayland.h b/include/backend/wayland.h index 61b349a5..d782584f 100644 --- a/include/backend/wayland.h +++ b/include/backend/wayland.h @@ -121,7 +121,7 @@ void create_wl_keyboard(struct wl_keyboard *wl_keyboard, struct wlr_wl_backend * void create_wl_touch(struct wl_touch *wl_touch, struct wlr_wl_backend *wl); struct wlr_wl_input_device *create_wl_input_device( struct wlr_wl_backend *backend, enum wlr_input_device_type type); -void create_wl_seat(struct wl_seat *wl_seat, struct wlr_wl_backend *wl); +bool create_wl_seat(struct wl_seat *wl_seat, struct wlr_wl_backend *wl); void destroy_wl_seats(struct wlr_wl_backend *wl); extern const struct wl_seat_listener seat_listener; |