src/layer.c: deal with wlroots scene graph running out of memory

This fixes an issue detected by the static analyzer.

Rather than setting up the new popup as usual return
a wayland error to the client and destroy the popup.
This commit is contained in:
Consolatis 2024-04-08 17:59:39 +02:00
parent 59c95ceb26
commit c80b55eb69

View file

@ -422,6 +422,13 @@ popup_handle_new_popup(struct wl_listener *listener, void *data)
struct wlr_xdg_popup *wlr_popup = data;
struct lab_layer_popup *new_popup = create_popup(wlr_popup,
lab_layer_popup->scene_tree);
if (!new_popup) {
wl_resource_post_no_memory(wlr_popup->resource);
wlr_xdg_popup_destroy(wlr_popup);
return;
}
new_popup->output_toplevel_sx_box =
lab_layer_popup->output_toplevel_sx_box;
}
@ -481,6 +488,12 @@ handle_new_popup(struct wl_listener *listener, void *data)
.height = output_box.height,
};
struct lab_layer_popup *popup = create_popup(wlr_popup, surface->tree);
if (!popup) {
wl_resource_post_no_memory(wlr_popup->resource);
wlr_xdg_popup_destroy(wlr_popup);
return;
}
popup->output_toplevel_sx_box = output_toplevel_sx_box;
if (surface->layer_surface->current.layer