From 8dcd71b3951bdd105c5782fbb319b5456ca70db8 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 4 May 2017 14:50:31 +1000 Subject: lid: remove the keyboard listener on remove and re-init the listener If the event listener is added, then removed again on a lid switch on/off event, the list is set to null. This can trigger two crashes: * when the keyboard is removed first, the call to libinput_device_remove_event_listener() dereferences the null pointer * when the switch is removed first, the call to device_destroy will find a remaining event listener and assert https://bugzilla.redhat.com/show_bug.cgi?id=1440927 Signed-off-by: Peter Hutterer --- test/test-lid.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'test') diff --git a/test/test-lid.c b/test/test-lid.c index 6b2fa3c..258f8e3 100644 --- a/test/test-lid.c +++ b/test/test-lid.c @@ -407,6 +407,35 @@ START_TEST(lid_open_on_key_touchpad_enabled) } END_TEST +START_TEST(lid_suspend_with_keyboard) +{ + struct libinput *li; + struct litest_device *keyboard; + struct litest_device *sw; + + li = litest_create_context(); + + sw = litest_add_device(li, LITEST_LID_SWITCH); + libinput_dispatch(li); + + keyboard = litest_add_device(li, LITEST_KEYBOARD); + libinput_dispatch(li); + + litest_lid_action(sw, LIBINPUT_SWITCH_STATE_ON); + litest_drain_events(li); + litest_lid_action(sw, LIBINPUT_SWITCH_STATE_OFF); + litest_drain_events(li); + + litest_delete_device(keyboard); + litest_drain_events(li); + + litest_delete_device(sw); + libinput_dispatch(li); + + libinput_unref(li); +} +END_TEST + START_TEST(lid_suspend_with_touchpad) { struct libinput *li; @@ -493,6 +522,7 @@ litest_setup_tests_lid(void) litest_add("lid:keyboard", lid_open_on_key, LITEST_SWITCH, LITEST_ANY); litest_add("lid:keyboard", lid_open_on_key_touchpad_enabled, LITEST_SWITCH, LITEST_ANY); + litest_add_no_device("lid:keyboard", lid_suspend_with_keyboard); litest_add_no_device("lid:disable_touchpad", lid_suspend_with_touchpad); litest_add_for_device("lid:buggy", lid_update_hw_on_key, LITEST_LID_SWITCH_SURFACE3); -- cgit v1.2.3