From 18897253d44449fadb1307a57eac7f4d203f3764 Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Fri, 24 Jun 2022 16:10:48 +0100 Subject: [PATCH] xwayland: Add compositor destroy listener to free allocation Otherwise we just leak this into the void. Not good. Signed-off-by: Daniel Stone --- compositor/xwayland.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/compositor/xwayland.c b/compositor/xwayland.c index 16827e6a..3de00f62 100644 --- a/compositor/xwayland.c +++ b/compositor/xwayland.c @@ -45,6 +45,7 @@ struct wet_xwayland { struct weston_compositor *compositor; + struct wl_listener compositor_destroy_listener; const struct weston_xwayland_api *api; struct weston_xwayland *xwayland; struct wl_event_source *display_fd_source; @@ -216,6 +217,21 @@ xserver_cleanup(struct weston_process *process, int status) wxw->client = NULL; } +static void +wxw_compositor_destroy(struct wl_listener *listener, void *data) +{ + struct wet_xwayland *wxw = + wl_container_of(listener, wxw, compositor_destroy_listener); + + /* Don't call xserver_exited because Xwayland's own destroy handler + * already does this for us ... */ + if (wxw->client) + kill(wxw->process.pid, SIGTERM); + + wl_list_remove(&wxw->process.link); + free(wxw); +} + int wet_load_xwayland(struct weston_compositor *comp) { @@ -245,9 +261,13 @@ wet_load_xwayland(struct weston_compositor *comp) wxw->compositor = comp; wxw->api = api; wxw->xwayland = xwayland; + wl_list_init(&wxw->process.link); wxw->process.cleanup = xserver_cleanup; + wxw->compositor_destroy_listener.notify = wxw_compositor_destroy; if (api->listen(xwayland, wxw, spawn_xserver) < 0) return -1; + wl_signal_add(&comp->destroy_signal, &wxw->compositor_destroy_listener); + return 0; }