From 2c64f36e8886d1f26daeb2a4ee79f3f9dd3d4c85 Mon Sep 17 00:00:00 2001 From: zhoulei Date: Tue, 13 Aug 2024 11:23:47 +0800 Subject: [PATCH] xwayland/xwm: listen shell destroy signal Otherwise we got invaild write in wl_list_remove. Fixes: e209fe2d0 ("Fix memory leak in xwayland.c") Signed-off-by: zhoulei --- include/xwayland/xwm.h | 1 + xwayland/xwm.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/xwayland/xwm.h b/include/xwayland/xwm.h index d3ecf5603..364095399 100644 --- a/include/xwayland/xwm.h +++ b/include/xwayland/xwm.h @@ -140,6 +140,7 @@ struct wlr_xwm { struct wl_listener compositor_new_surface; struct wl_listener compositor_destroy; struct wl_listener shell_v1_new_surface; + struct wl_listener shell_v1_destroy; struct wl_listener seat_set_selection; struct wl_listener seat_set_primary_selection; struct wl_listener seat_start_drag; diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 6b85829dc..f25e4734b 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -1859,6 +1859,16 @@ static void handle_shell_v1_new_surface(struct wl_listener *listener, } } +static void handle_shell_v1_destroy(struct wl_listener *listener, + void *data) { + struct wlr_xwm *xwm = + wl_container_of(listener, xwm, shell_v1_destroy); + wl_list_remove(&xwm->shell_v1_new_surface.link); + wl_list_remove(&xwm->shell_v1_destroy.link); + wl_list_init(&xwm->shell_v1_new_surface.link); + wl_list_init(&xwm->shell_v1_destroy.link); +} + void wlr_xwayland_surface_activate(struct wlr_xwayland_surface *xsurface, bool activated) { struct wlr_xwayland_surface *focused = xsurface->xwm->focus_surface; @@ -1986,6 +1996,7 @@ void xwm_destroy(struct wlr_xwm *xwm) { wl_list_remove(&xwm->compositor_new_surface.link); wl_list_remove(&xwm->compositor_destroy.link); wl_list_remove(&xwm->shell_v1_new_surface.link); + wl_list_remove(&xwm->shell_v1_destroy.link); xcb_disconnect(xwm->xcb_conn); struct pending_startup_id *pending, *next; @@ -2331,6 +2342,9 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *xwayland, int wm_fd) { xwm->shell_v1_new_surface.notify = handle_shell_v1_new_surface; wl_signal_add(&xwayland->shell_v1->events.new_surface, &xwm->shell_v1_new_surface); + xwm->shell_v1_destroy.notify = handle_shell_v1_destroy; + wl_signal_add(&xwayland->shell_v1->events.destroy, + &xwm->shell_v1_destroy); xwm_create_wm_window(xwm);