Destroy associated reference counted objects when destroying context
authorJonas Ådahl <jadahl@gmail.com>
Tue, 31 Dec 2013 15:11:03 +0000 (16:11 +0100)
committerJonas Ådahl <jadahl@gmail.com>
Fri, 3 Jan 2014 21:38:42 +0000 (22:38 +0100)
This avoids issues with device and seat objects depending on a valid
context.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
src/libinput.c
src/libinput.h

index b566ff9..989fd8c 100644 (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
index b92b206..0d03073 100644 (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
  */