Re: [PATCH weston] compositor-wayland: handle wl_keyboard.enter(NULL)

2018-03-09 Thread Daniel Stone
Hi Pekka,

On 22 February 2018 at 14:54, Pekka Paalanen  wrote:
> Destroying an output (wl_surface) can race against the parent compositor
> sending wl_keyboard.enter. When this race is lost, wayland-backend
> receives wl_keyboard.enter with a NULL wl_surface for the surface it
> just destroyed.
>
> Handle this case by ignoring such enter events. Since it is
> theoretically possible to follow enter with key events, drop those too.
>
> The modifiers event is sent before enter, so we cannot drop that on the
> same condition.
>
> wl_keyboard.leave handler seems to already handle the NULL focus case,
> but there is a question if the notify_keyboard_focus_out() call should
> be avoided.
>
> This patch fixes a hard to reproduce crash. I was running weston/x11
> with two outputs, and weston/wayland --sprawl inside that, then closing
> the parent compositor windows one by one. Sometimes it would trigger
> this crash.

Thanks! This looks good to me. Whilst looking, I noticed pointer had a
similar issue, so I've just sent a patch for that now.

Cheers,
Daniel
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston] compositor-wayland: handle wl_keyboard.enter(NULL)

2018-02-22 Thread Pekka Paalanen
From: Pekka Paalanen 

Destroying an output (wl_surface) can race against the parent compositor
sending wl_keyboard.enter. When this race is lost, wayland-backend
receives wl_keyboard.enter with a NULL wl_surface for the surface it
just destroyed.

Handle this case by ignoring such enter events. Since it is
theoretically possible to follow enter with key events, drop those too.

The modifiers event is sent before enter, so we cannot drop that on the
same condition.

wl_keyboard.leave handler seems to already handle the NULL focus case,
but there is a question if the notify_keyboard_focus_out() call should
be avoided.

This patch fixes a hard to reproduce crash. I was running weston/x11
with two outputs, and weston/wayland --sprawl inside that, then closing
the parent compositor windows one by one. Sometimes it would trigger
this crash.

Signed-off-by: Pekka Paalanen 
---
 libweston/compositor-wayland.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/libweston/compositor-wayland.c b/libweston/compositor-wayland.c
index c6b92611..9c401d2e 100644
--- a/libweston/compositor-wayland.c
+++ b/libweston/compositor-wayland.c
@@ -1858,6 +1858,11 @@ input_handle_keyboard_enter(void *data,
weston_output_schedule_repaint(>base);
}
 
+   if (!surface) {
+   input->keyboard_focus = NULL;
+   return;
+   }
+
input->keyboard_focus = wl_surface_get_user_data(surface);
input->keyboard_focus->keyboard_count++;
 
@@ -1907,6 +1912,9 @@ input_handle_key(void *data, struct wl_keyboard *keyboard,
struct wayland_input *input = data;
struct timespec ts;
 
+   if (!input->keyboard_focus)
+   return;
+
timespec_from_msec(, time);
 
input->key_serial = serial;
-- 
2.16.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel