[PATCH weston 5/6] input: Free the memory allocated to store the device resource lists

Rob Bradford robert.bradford at intel.com
Tue Aug 13 11:53:14 PDT 2013


From: Rob Bradford <rob at linux.intel.com>

v2: Walk the array manually as wl_array_for_each is bytewise we're
storing pointers that we need to free.
---
 src/input.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/src/input.c b/src/input.c
index 1fa3f48..396e35e 100644
--- a/src/input.c
+++ b/src/input.c
@@ -365,10 +365,17 @@ weston_pointer_create(void)
 WL_EXPORT void
 weston_pointer_destroy(struct weston_pointer *pointer)
 {
+	void **p;
+
 	if (pointer->sprite)
 		pointer_unmap_sprite(pointer);
 
-	/* XXX: What about pointer->resource_list? */
+	for (p = pointer->resources.data;
+	     p < (void **)(pointer->resources.data + pointer->resources.size);
+	     p+= sizeof(struct wl_list *))
+		free(*p);
+	wl_array_release(&pointer->resources);
+
 	if (!wl_list_empty(pointer->focus_resource_list))
 		wl_list_remove(&pointer->focus_listener.link);
 	free(pointer);
@@ -398,7 +405,14 @@ weston_keyboard_create(void)
 WL_EXPORT void
 weston_keyboard_destroy(struct weston_keyboard *keyboard)
 {
-	/* XXX: What about keyboard->resource_list? */
+	void **p;
+
+	for (p = keyboard->resources.data;
+	     p < (void **)(keyboard->resources.data + keyboard->resources.size);
+	     p+= sizeof(struct wl_list *))
+		free(*p);
+	wl_array_release(&keyboard->resources);
+
 	if (!wl_list_empty(keyboard->focus_resource_list))
 		wl_list_remove(&keyboard->focus_listener.link);
 	wl_array_release(&keyboard->keys);
@@ -428,7 +442,14 @@ weston_touch_create(void)
 WL_EXPORT void
 weston_touch_destroy(struct weston_touch *touch)
 {
-	/* XXX: What about touch->resource_list? */
+	void **p;
+
+	for (p = touch->resources.data;
+	     p < (void **)(touch->resources.data + touch->resources.size);
+	     p+= sizeof(struct wl_list *))
+		free(*p);
+	wl_array_release(&touch->resources);
+
 	if (!wl_list_empty(touch->focus_resource_list))
 		wl_list_remove(&touch->focus_listener.link);
 	free(touch);
-- 
1.8.3.1



More information about the wayland-devel mailing list