From 78c2b71c23794c1e7552b942dbaa4222ac301719 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jonas=20=C3=85dahl?= Date: Wed, 22 Jan 2014 23:45:44 +0100 Subject: [PATCH] Simplify device reference counting of events MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This also makes DEVICE_ADDED/REMOVED events own a reference, which is necessary to not have libinput_event_get_device() potentially returning an invalid pointer. Signed-off-by: Jonas Ådahl --- src/libinput.c | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/src/libinput.c b/src/libinput.c index 2413c8e..92ba414 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -431,22 +431,8 @@ libinput_event_destroy(struct libinput_event *event) if (event == NULL) return; - switch (libinput_event_get_type(event)) { - case LIBINPUT_EVENT_NONE: - abort(); /* not used as actual event type */ - case LIBINPUT_EVENT_DEVICE_ADDED: - case LIBINPUT_EVENT_DEVICE_REMOVED: - break; - case LIBINPUT_EVENT_KEYBOARD_KEY: - case LIBINPUT_EVENT_POINTER_MOTION: - case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: - case LIBINPUT_EVENT_POINTER_BUTTON: - case LIBINPUT_EVENT_POINTER_AXIS: - case LIBINPUT_EVENT_TOUCH_TOUCH: - case LIBINPUT_EVENT_TOUCH_FRAME: + if (event->device) libinput_device_unref(event->device); - break; - } free(event); } @@ -850,22 +836,8 @@ libinput_post_event(struct libinput *libinput, libinput->events_len = events_len; } - switch (libinput_event_get_type(event)) { - case LIBINPUT_EVENT_NONE: - abort(); /* not used as actual event type */ - case LIBINPUT_EVENT_DEVICE_ADDED: - case LIBINPUT_EVENT_DEVICE_REMOVED: - break; - case LIBINPUT_EVENT_KEYBOARD_KEY: - case LIBINPUT_EVENT_POINTER_MOTION: - case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: - case LIBINPUT_EVENT_POINTER_BUTTON: - case LIBINPUT_EVENT_POINTER_AXIS: - case LIBINPUT_EVENT_TOUCH_TOUCH: - case LIBINPUT_EVENT_TOUCH_FRAME: + if (event->device) libinput_device_ref(event->device); - break; - } libinput->events_count = events_count; events[libinput->events_in] = event; -- 2.7.4