[PATCH 5/5] shm: Plug leak in shm_create_pool()

Kristian Høgsberg hoegsberg at gmail.com
Mon Jul 9 18:14:57 PDT 2012


On Mon, Jul 09, 2012 at 11:35:57AM +0200, Martin Olsson wrote:
> ---
>  src/wayland-shm.c |   15 +++++++++------
>  1 file changed, 9 insertions(+), 6 deletions(-)
> 
> diff --git a/src/wayland-shm.c b/src/wayland-shm.c
> index 62afc3b..7565623 100644
> --- a/src/wayland-shm.c
> +++ b/src/wayland-shm.c
> @@ -188,29 +188,27 @@ shm_create_pool(struct wl_client *client, struct wl_resource *resource,
>  	pool = malloc(sizeof *pool);
>  	if (pool == NULL) {
>  		wl_resource_post_no_memory(resource);
> -		close(fd);
> -		return;
> +		goto err_close;
>  	}
>  
>  	if (size <= 0) {
>  		wl_resource_post_error(resource,
>  				       WL_SHM_ERROR_INVALID_STRIDE,
>  				       "invalid size (%d)", size);
> -		close(fd);
> -		return;
> +		goto err_free;
>  	}
>  
>  	pool->refcount = 1;
>  	pool->size = size;
>  	pool->data = mmap(NULL, size,
>  			  PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
> -	close(fd);
>  	if (pool->data == MAP_FAILED) {
>  		wl_resource_post_error(resource,
>  				       WL_SHM_ERROR_INVALID_FD,
>  				       "failed mmap fd %d", fd);
> -		return;
> +		goto err_free;
>  	}
> +	close(fd);
>  
>  	pool->resource.object.id = id;
>  	pool->resource.object.interface = &wl_shm_pool_interface;
> @@ -222,6 +220,11 @@ shm_create_pool(struct wl_client *client, struct wl_resource *resource,
>  	pool->resource.destroy = destroy_pool;
>  
>  	wl_client_add_resource(client, &pool->resource);

We're missing a return here.  I've added it in a follow-on commit.

Kristian

> +
> +err_close:
> +	close(fd);
> +err_free:
> +	free(pool);
>  }
>  
>  static const struct wl_shm_interface shm_interface = {
> -- 
> 1.7.9.5
> 
> _______________________________________________
> 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