]> git.mdlowis.com Git - proto/labwc.git/commitdiff
src/layer.c: deal with wlroots scene graph running out of memory
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Mon, 8 Apr 2024 15:59:39 +0000 (17:59 +0200)
committerConsolatis <35009135+Consolatis@users.noreply.github.com>
Wed, 10 Apr 2024 06:14:59 +0000 (08:14 +0200)
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.

src/layers.c

index fe897f9ab74d5b6922fca7e53c3a9af27a0c2015..4a853fe3e40d9ac4913f35642031f8266799d28e 100644 (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