[PATCH wayland] Free non-legacy resources inside wl_resource_destroy

Kristian Høgsberg hoegsberg at gmail.com
Thu Jun 20 12:16:36 PDT 2013


On Tue, Jun 18, 2013 at 12:42:40PM -0500, Jason Ekstrand wrote:
> This commit makes wl_resource_destroy automatically free all non-legacy
> resource structures.  Since wl_resource is now an opaque structure it
> doesn't make sense for the clients to be freeing it.  This checks to make
> sure that it was added through wl_client_add_object or wl_client_new_object
> and not wl_client_add_resource before it frees it.  This way if it is a
> legacy resources embedded in a structure somewhere we don't have an invalid
> free.

Thanks, applied.

> Signed-off-by: Jason Ekstrand <jason at jlekstrand.net>
> ---
>  src/wayland-server.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/src/wayland-server.c b/src/wayland-server.c
> index e2776ff..28a10cc 100644
> --- a/src/wayland-server.c
> +++ b/src/wayland-server.c
> @@ -429,6 +429,9 @@ wl_resource_destroy(struct wl_resource *resource)
>  	id = resource->object.id;
>  	destroy_resource(resource, NULL);
>  
> +	if (!(wl_map_lookup_flags(&client->objects, id) & WL_MAP_ENTRY_LEGACY))
> +		free(resource);
> +
>  	if (id < WL_SERVER_ID_START) {
>  		if (client->display_resource) {
>  			wl_resource_queue_event(client->display_resource,
> @@ -986,7 +989,7 @@ wl_client_add_object(struct wl_client *client,
>  
>  	wl_resource_init(resource, interface, implementation, id, data);
>  	resource->client = client;
> -	resource->destroy = (void *) free;
> +	resource->destroy = NULL;
>  
>  	if (wl_map_insert_at(&client->objects, 0, resource->object.id, resource) < 0) {
>  		wl_resource_post_error(client->display_resource,
> -- 
> 1.8.1.4
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel


More information about the wayland-devel mailing list