From cd6a65bf3758286ec8fdb1a99eeab1a5a5588cf6 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 7 Jan 2014 15:45:55 +1000 Subject: [PATCH] Drop the destroyed sources list on libinput_destroy() ==2772== 40 bytes in 1 blocks are definitely lost in loss record 3 of 4 ==2772== at 0x4A0645D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==2772== by 0x405EC7: libinput_add_fd (libinput.c:335) ==2772== by 0x40B346: udev_input_enable (udev-seat.c:268) ==2772== by 0x40B5E7: libinput_create_from_udev (udev-seat.c:369) Signed-off-by: Peter Hutterer --- src/libinput.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/libinput.c b/src/libinput.c index e30b6a29..e9c6d5c6 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -393,6 +393,16 @@ libinput_device_destroy(struct libinput_device *device); static void libinput_seat_destroy(struct libinput_seat *seat); +static void +libinput_drop_destroyed_sources(struct libinput *libinput) +{ + struct libinput_source *source, *next; + + list_for_each_safe(source, next, &libinput->source_destroy_list, link) + free(source); + list_init(&libinput->source_destroy_list); +} + LIBINPUT_EXPORT void libinput_destroy(struct libinput *libinput) { @@ -405,6 +415,9 @@ libinput_destroy(struct libinput *libinput) while ((event = libinput_get_event(libinput))) libinput_event_destroy(event); + + libinput_drop_destroyed_sources(libinput); + free(libinput->events); list_for_each_safe(seat, next_seat, &libinput->seat_list, link) { @@ -569,7 +582,7 @@ libinput_get_fd(struct libinput *libinput) LIBINPUT_EXPORT int libinput_dispatch(struct libinput *libinput) { - struct libinput_source *source, *next; + struct libinput_source *source; struct epoll_event ep[32]; int i, count; @@ -585,9 +598,7 @@ libinput_dispatch(struct libinput *libinput) source->dispatch(source->user_data); } - list_for_each_safe(source, next, &libinput->source_destroy_list, link) - free(source); - list_init(&libinput->source_destroy_list); + libinput_drop_destroyed_sources(libinput); return 0; }