From a33ede4c43dfe7be89079dabfff84a99f942534d Mon Sep 17 00:00:00 2001 From: Alexander Orzechowski Date: Fri, 4 Mar 2022 19:23:27 -0500 Subject: [PATCH] view: init function should return a success bool --- include/sway/tree/view.h | 2 +- sway/desktop/xdg_shell.c | 5 ++++- sway/desktop/xwayland.c | 5 ++++- sway/tree/view.c | 3 ++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index 0dcbf1aa6..b63936ad6 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -304,7 +304,7 @@ void view_for_each_popup_surface(struct sway_view *view, // view implementation -void view_init(struct sway_view *view, enum sway_view_type type, +bool view_init(struct sway_view *view, enum sway_view_type type, const struct sway_view_impl *impl); void view_destroy(struct sway_view *view); diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index 8da922d50..9ce7d611c 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c @@ -519,7 +519,10 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) { return; } - view_init(&xdg_shell_view->view, SWAY_VIEW_XDG_SHELL, &view_impl); + if (!view_init(&xdg_shell_view->view, SWAY_VIEW_XDG_SHELL, &view_impl)) { + free(xdg_shell_view); + return; + } xdg_shell_view->view.wlr_xdg_toplevel = xdg_surface->toplevel; xdg_shell_view->map.notify = handle_map; diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 7c5dde530..7453c07d6 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -712,7 +712,10 @@ struct sway_xwayland_view *create_xwayland_view(struct wlr_xwayland_surface *xsu return NULL; } - view_init(&xwayland_view->view, SWAY_VIEW_XWAYLAND, &view_impl); + if (!view_init(&xwayland_view->view, SWAY_VIEW_XWAYLAND, &view_impl)) { + free(xwayland_view); + return NULL; + } xwayland_view->view.wlr_xwayland_surface = xsurface; wl_signal_add(&xsurface->events.destroy, &xwayland_view->destroy); diff --git a/sway/tree/view.c b/sway/tree/view.c index 0004ed141..9a24cfbe5 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -33,7 +33,7 @@ #include "pango.h" #include "stringop.h" -void view_init(struct sway_view *view, enum sway_view_type type, +bool view_init(struct sway_view *view, enum sway_view_type type, const struct sway_view_impl *impl) { view->type = type; view->impl = impl; @@ -42,6 +42,7 @@ void view_init(struct sway_view *view, enum sway_view_type type, view->allow_request_urgent = true; view->shortcuts_inhibit = SHORTCUTS_INHIBIT_DEFAULT; wl_signal_init(&view->events.unmap); + return true; } void view_destroy(struct sway_view *view) {