tree-wide: use die_if_null() for wlr_scene alloc failures
Some checks failed
labwc.github.io / notify (push) Has been cancelled

wlr_scene_*_create() functions all allocate memory via calloc() and
return NULL if the allocation fails. Previously, the failures were
handled in any of 3 different ways:

 - sending a wayland protocol error
 - exiting labwc with an error
 - segfault (no NULL check at all)

Since labwc does not attempt to survive heap exhaustion in other
allocation paths (such as `znew`), it seems more consistent to use the
same die_if_null() check used in those paths to exit with an error.

For the three most common create() functions (tree, rect, buffer),
add small lab_wlr_ wrappers to common/scene-helpers.
This commit is contained in:
John Lindgren 2026-02-23 16:34:36 -05:00 committed by Johan Malm
parent c4effef0ec
commit 16c5373be5
27 changed files with 155 additions and 141 deletions

View file

@ -13,6 +13,7 @@
#include "common/box.h"
#include "common/macros.h"
#include "common/mem.h"
#include "common/scene-helpers.h"
#include "config/rcxml.h"
#include "decorations.h"
#include "foreign-toplevel/foreign.h"
@ -193,7 +194,7 @@ center_fullscreen_if_needed(struct view *view)
if (!xdg_view->fullscreen_bg) {
const float black[4] = {0, 0, 0, 1};
xdg_view->fullscreen_bg =
wlr_scene_rect_create(view->scene_tree, 0, 0, black);
lab_wlr_scene_rect_create(view->scene_tree, 0, 0, black);
wlr_scene_node_lower_to_bottom(&xdg_view->fullscreen_bg->node);
}
@ -984,18 +985,14 @@ handle_new_xdg_toplevel(struct wl_listener *listener, void *data)
}
view->workspace = server->workspaces.current;
view->scene_tree = wlr_scene_tree_create(
view->scene_tree = lab_wlr_scene_tree_create(
view->workspace->view_trees[VIEW_LAYER_NORMAL]);
wlr_scene_node_set_enabled(&view->scene_tree->node, false);
struct wlr_scene_tree *tree = wlr_scene_xdg_surface_create(
view->scene_tree, xdg_surface);
if (!tree) {
/* TODO: might need further clean up */
wl_resource_post_no_memory(xdg_surface->resource);
free(xdg_toplevel_view);
return;
}
die_if_null(tree);
view->content_tree = tree;
node_descriptor_create(&view->scene_tree->node,
LAB_NODE_VIEW, view, /*data*/ NULL);