Destroy associated reference counted objects when destroying context

This avoids issues with device and seat objects depending on a valid
context.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
This commit is contained in:
Jonas Ådahl 2013-12-31 16:11:03 +01:00
parent e637b9b0f5
commit 68619ec714
2 changed files with 26 additions and 8 deletions

View file

@ -380,6 +380,12 @@ libinput_init(struct libinput *libinput,
return 0;
}
static void
libinput_device_destroy(struct libinput_device *device);
static void
libinput_seat_destroy(struct libinput_seat *seat);
LIBINPUT_EXPORT void
libinput_destroy(struct libinput *libinput)
{
@ -395,9 +401,9 @@ libinput_destroy(struct libinput *libinput)
list_for_each_safe(device, next_device,
&seat->devices_list,
link)
libinput_device_unref(device);
libinput_device_destroy(device);
libinput_seat_unref(seat);
libinput_seat_destroy(seat);
}
close(libinput->epoll_fd);
@ -481,14 +487,19 @@ libinput_seat_ref(struct libinput_seat *seat)
seat->refcount++;
}
static void
libinput_seat_destroy(struct libinput_seat *seat)
{
free(seat->name);
udev_seat_destroy((struct udev_seat *) seat);
}
LIBINPUT_EXPORT void
libinput_seat_unref(struct libinput_seat *seat)
{
seat->refcount--;
if (seat->refcount == 0) {
free(seat->name);
udev_seat_destroy((struct udev_seat *) seat);
}
if (seat->refcount == 0)
libinput_seat_destroy(seat);
}
LIBINPUT_EXPORT void
@ -523,12 +534,18 @@ libinput_device_ref(struct libinput_device *device)
device->refcount++;
}
static void
libinput_device_destroy(struct libinput_device *device)
{
evdev_device_destroy((struct evdev_device *) device);
}
LIBINPUT_EXPORT void
libinput_device_unref(struct libinput_device *device)
{
device->refcount--;
if (device->refcount == 0)
evdev_device_destroy((struct evdev_device *) device);
libinput_device_destroy(device);
}
LIBINPUT_EXPORT int

View file

@ -528,7 +528,8 @@ libinput_suspend(struct libinput *libinput);
/**
* @ingroup base
*
* Destroy the libinput context.
* Destroy the libinput context. After this, object references associated with
* the destroyed context are invalid and may not be interacted with.
*
* @param libinput A previously initialized libinput context
*/