kiosk-shell: Keep track of seats created and destroy them at end

kiosk_shell_destroy() will free up weston_desktop, but still keeping
listeners set-up (keyboard/seat/caps), which will fire
when the the compositor is stopped/shutdown by clients still connected.

This patch maintains a list of seats and uses it to remove any listeners
when calling kiosk_shell_destroy(). desktop-shell and ivi-shell do not
appear to be using weston_desktop_destroy() in their respective destroy
parts.

This avoids an illegal access happening when calling one of the
listeners, after weston_desktop has been free'ed, like the following:

==2002==    at 0x10F3F8FD: weston_desktop_get_display (libweston-desktop.c:125)
==2002==    by 0x10F450A7: weston_desktop_xdg_surface_schedule_configure (xdg-shell.c:1022)
==2002==    by 0x10F44793: weston_desktop_xdg_toplevel_set_activated (xdg-shell.c:643)
==2002==    by 0x10F41AA5: weston_desktop_surface_set_activated (surface.c:468)
==2002==    by 0x10F32E7E: kiosk_shell_seat_handle_keyboard_focus (kiosk-shell.c:329)
==2002==    by 0x4A726A7: wl_signal_emit (wayland-server-core.h:478)
==2002==    by 0x4A75BD1: weston_keyboard_set_focus (input.c:1586)
==2002==    by 0x4A776FE: notify_keyboard_focus_out (input.c:2314)
==2002==    by 0x5902BC1: udev_seat_destroy (libinput-seat.c:469)
==2002==    by 0x59028C5: udev_input_destroy (libinput-seat.c:375)
==2002==    by 0x58F0449: drm_destroy (drm.c:2571)
==2002==    by 0x4A6EE39: weston_compositor_destroy (compositor.c:7814)
==2002==  Address 0x10bd1780 is 0 bytes inside a block of size 152 free'd
==2002==    at 0x48399AB: free (vg_replace_malloc.c:538)
==2002==    by 0x10F3F8DA: weston_desktop_destroy (libweston-desktop.c:112)
==2002==    by 0x10F34357: kiosk_shell_destroy (kiosk-shell.c:1009)
==2002==    by 0x4A5F618: wl_signal_emit (wayland-server-core.h:478)
==2002==    by 0x4A6EE06: weston_compositor_destroy (compositor.c:7809)
==2002==    by 0x4855548: wet_main (main.c:3420)
==2002==    by 0x109154: main (executable.c:33)
==2002==  Block was alloc'd at
==2002==    at 0x483AB65: calloc (vg_replace_malloc.c:760)
==2002==    by 0x10F3F681: zalloc (zalloc.h:38)
==2002==    by 0x10F3F724: weston_desktop_create (libweston-desktop.c:65)
==2002==    by 0x10F34458: wet_shell_init (kiosk-shell.c:1045)
==2002==    by 0x484F83D: wet_load_shell (main.c:924)
==2002==    by 0x48552D3: wet_main (main.c:3361)
==2002==    by 0x109154: main (executable.c:33)

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
dev
Marius Vlad 4 years ago
parent 79491b41f5
commit 092130c4bf
  1. 32
      kiosk-shell/kiosk-shell.c
  2. 3
      kiosk-shell/kiosk-shell.h

@ -341,6 +341,17 @@ kiosk_shell_seat_handle_keyboard_focus(struct wl_listener *listener, void *data)
} }
} }
static void
kiosk_shell_seat_destroy(struct kiosk_shell_seat *shseat)
{
wl_list_remove(&shseat->keyboard_focus_listener.link);
wl_list_remove(&shseat->caps_changed_listener.link);
wl_list_remove(&shseat->seat_destroy_listener.link);
wl_list_remove(&shseat->link);
free(shseat);
}
static void static void
kiosk_shell_seat_handle_destroy(struct wl_listener *listener, void *data) kiosk_shell_seat_handle_destroy(struct wl_listener *listener, void *data)
{ {
@ -348,10 +359,7 @@ kiosk_shell_seat_handle_destroy(struct wl_listener *listener, void *data)
container_of(listener, container_of(listener,
struct kiosk_shell_seat, seat_destroy_listener); struct kiosk_shell_seat, seat_destroy_listener);
wl_list_remove(&shseat->keyboard_focus_listener.link); kiosk_shell_seat_destroy(shseat);
wl_list_remove(&shseat->caps_changed_listener.link);
wl_list_remove(&shseat->seat_destroy_listener.link);
free(shseat);
} }
static void static void
@ -375,7 +383,7 @@ kiosk_shell_seat_handle_caps_changed(struct wl_listener *listener, void *data)
} }
static struct kiosk_shell_seat * static struct kiosk_shell_seat *
kiosk_shell_seat_create(struct weston_seat *seat) kiosk_shell_seat_create(struct kiosk_shell *shell, struct weston_seat *seat)
{ {
struct kiosk_shell_seat *shseat; struct kiosk_shell_seat *shseat;
@ -398,6 +406,8 @@ kiosk_shell_seat_create(struct weston_seat *seat)
&shseat->caps_changed_listener); &shseat->caps_changed_listener);
kiosk_shell_seat_handle_caps_changed(&shseat->caps_changed_listener, NULL); kiosk_shell_seat_handle_caps_changed(&shseat->caps_changed_listener, NULL);
wl_list_insert(&shell->seat_list, &shseat->link);
return shseat; return shseat;
} }
@ -986,7 +996,9 @@ static void
kiosk_shell_handle_seat_created(struct wl_listener *listener, void *data) kiosk_shell_handle_seat_created(struct wl_listener *listener, void *data)
{ {
struct weston_seat *seat = data; struct weston_seat *seat = data;
kiosk_shell_seat_create(seat); struct kiosk_shell *shell =
container_of(listener, struct kiosk_shell, seat_created_listener);
kiosk_shell_seat_create(shell, seat);
} }
static void static void
@ -995,6 +1007,7 @@ kiosk_shell_destroy(struct wl_listener *listener, void *data)
struct kiosk_shell *shell = struct kiosk_shell *shell =
container_of(listener, struct kiosk_shell, destroy_listener); container_of(listener, struct kiosk_shell, destroy_listener);
struct kiosk_shell_output *shoutput, *tmp; struct kiosk_shell_output *shoutput, *tmp;
struct kiosk_shell_seat *shseat, *shseat_next;
wl_list_remove(&shell->destroy_listener.link); wl_list_remove(&shell->destroy_listener.link);
wl_list_remove(&shell->output_created_listener.link); wl_list_remove(&shell->output_created_listener.link);
@ -1006,6 +1019,10 @@ kiosk_shell_destroy(struct wl_listener *listener, void *data)
kiosk_shell_output_destroy(shoutput); kiosk_shell_output_destroy(shoutput);
} }
wl_list_for_each_safe(shseat, shseat_next, &shell->seat_list, link) {
kiosk_shell_seat_destroy(shseat);
}
weston_desktop_destroy(shell->desktop); weston_desktop_destroy(shell->desktop);
free(shell); free(shell);
@ -1047,8 +1064,9 @@ wet_shell_init(struct weston_compositor *ec,
if (!shell->desktop) if (!shell->desktop)
return -1; return -1;
wl_list_init(&shell->seat_list);
wl_list_for_each(seat, &ec->seat_list, link) wl_list_for_each(seat, &ec->seat_list, link)
kiosk_shell_seat_create(seat); kiosk_shell_seat_create(shell, seat);
shell->seat_created_listener.notify = kiosk_shell_handle_seat_created; shell->seat_created_listener.notify = kiosk_shell_handle_seat_created;
wl_signal_add(&ec->seat_created_signal, &shell->seat_created_listener); wl_signal_add(&ec->seat_created_signal, &shell->seat_created_listener);

@ -41,6 +41,7 @@ struct kiosk_shell {
struct weston_layer normal_layer; struct weston_layer normal_layer;
struct wl_list output_list; struct wl_list output_list;
struct wl_list seat_list;
}; };
struct kiosk_shell_surface { struct kiosk_shell_surface {
@ -75,6 +76,8 @@ struct kiosk_shell_seat {
struct wl_listener caps_changed_listener; struct wl_listener caps_changed_listener;
struct wl_listener keyboard_focus_listener; struct wl_listener keyboard_focus_listener;
struct wl_list link; /** kiosk_shell::seat_list */
}; };
struct kiosk_shell_output { struct kiosk_shell_output {

Loading…
Cancel
Save