From 9467eba60de0b6d6021c74043b9431c8a59bded7 Mon Sep 17 00:00:00 2001 From: JengHyun Kang Date: Wed, 7 Jun 2017 20:10:07 +0900 Subject: [PATCH] evdev: free aux_data list when device is destroy Change-Id: I76f8df6b8fed1d01540c1430247ffc00dc28dfc5 --- src/evdev-fallback.c | 23 +++++++++++++++++++++-- src/evdev.c | 17 +++++++++++++++-- src/evdev.h | 3 +++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/evdev-fallback.c b/src/evdev-fallback.c index 6b9b4a65..6f175555 100644 --- a/src/evdev-fallback.c +++ b/src/evdev-fallback.c @@ -1535,6 +1535,25 @@ failed: } } +static void +fallback_device_interface_free_aux_data(struct evdev_dispatch *evdev_dispatch) +{ + int i; + struct fallback_dispatch *dispatch; + struct mt_aux_data *aux_data; + + dispatch = fallback_dispatch(evdev_dispatch); + + for (i = 0; i < (int)dispatch->mt.slots_len; i++) { + list_for_each_safe(aux_data, &dispatch->mt.aux_data_list[i], link) { + list_remove(&aux_data->link); + free(aux_data); + } + list_remove(&dispatch->mt.aux_data_list[i]); + } + free(dispatch->mt.aux_data_list); +} + struct evdev_dispatch_device_interface fallback_device_interface = { .set_aux_data = fallback_device_interface_set_aux_data }; @@ -1689,10 +1708,10 @@ fallback_dispatch_init_slots(struct fallback_dispatch *dispatch, ABS_MT_TOOL_TYPE); dispatch->mt.aux_data_list = calloc(num_slots, sizeof(struct list)); - if (device->mt.aux_data_list) { + if (dispatch->mt.aux_data_list) { int i; for (i = 0; i < num_slots; i++) { - list_init(&device->mt.aux_data_list[i]); + list_init(&dispatch->mt.aux_data_list[i]); } } else diff --git a/src/evdev.c b/src/evdev.c index 9bd5d8de..21403708 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -3194,6 +3194,7 @@ evdev_device_destroy(struct evdev_device *device) libinput_seat_unref(device->base.seat); libevdev_free(device->evdev); udev_device_unref(device->udev_device); + evdev_device_free_aux_data(device); free(device); } @@ -3261,7 +3262,19 @@ evdev_device_set_aux_data(struct evdev_device *device, uint32_t code) if (!dispatch) return; if (!dispatch->device_interface) return; - if (dispatch->device_interface->set_auxdata) { - dispatch->device_interface->set_auxdata(dispatch, code); + if (dispatch->device_interface->set_aux_data) { + dispatch->device_interface->set_aux_data(dispatch, code); + } +} + +void +evdev_device_free_aux_data(struct evdev_device *device) +{ + struct evdev_dispatch *dispatch = device->dispatch; + if (!dispatch) return; + if (!dispatch->device_interface) return; + + if (dispatch->device_interface->free_aux_data) { + dispatch->device_interface->free_aux_data(dispatch, code); } } diff --git a/src/evdev.h b/src/evdev.h index 262e5899..bf15ea00 100644 --- a/src/evdev.h +++ b/src/evdev.h @@ -356,6 +356,7 @@ struct evdev_dispatch_interface { struct evdev_dispatch_device_interface { void (*set_aux_data) (struct evdev_dispatch *dispatch, uint32_t code); + void (*free_aux_data) (struct evdev_dispatch *dispatch); }; enum evdev_dispatch_type { @@ -1077,4 +1078,6 @@ evdev_device_has_aux_data(struct evdev_device *device, uint32_t code); void evdev_device_set_aux_data(struct evdev_device *device, uint32_t code); +void +evdev_device_free_aux_data(struct evdev_device *device); #endif /* EVDEV_H */ -- 2.34.1