[PATCH wayland 2/2] cursor: fix some leaks

Pekka Paalanen ppaalanen at gmail.com
Tue Jul 10 00:27:58 PDT 2012


On Mon, 9 Jul 2012 18:02:51 -0400
Kristian Høgsberg <hoegsberg at gmail.com> wrote:

> On Mon, Jul 09, 2012 at 01:34:35PM +0300, Pekka Paalanen wrote:
> > - don't leak memory in shm_pool_create() on failure
> > - don't leak fd in shm_pool_destroy()
> > - return NULL from wl_cursor_theme_load() if pool fails
> > 
> > Tha last one fixes a segfault, when shm_pool_create() has failed.
> 
> I think Martins series fixed this, right?

At least most of it, yes, but depending on what you chose to apply,
there will probably be some conflicts.

I'll check what you actually merged, and rebase the rest and re-send,
if there's anything left.


Thanks,
pq

> > Signed-off-by: Pekka Paalanen <ppaalanen at gmail.com>
> > ---
> >  cursor/wayland-cursor.c |   11 ++++++++++-
> >  1 files changed, 10 insertions(+), 1 deletions(-)
> > 
> > diff --git a/cursor/wayland-cursor.c b/cursor/wayland-cursor.c
> > index 1a312b0..bd9dfc7 100644
> > --- a/cursor/wayland-cursor.c
> > +++ b/cursor/wayland-cursor.c
> > @@ -49,14 +49,17 @@ shm_pool_create(struct wl_shm *shm, int size)
> >  		return NULL;
> >  
> >  	pool->fd = os_create_anonymous_file(size);
> > -	if (pool->fd < 0)
> > +	if (pool->fd < 0) {
> > +		free(pool);
> >  		return NULL;
> > +	}
> >  
> >  	pool->data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED,
> >  			  pool->fd, 0);
> >  
> >  	if (pool->data == MAP_FAILED) {
> >  		close(pool->fd);
> > +		free(pool);
> >  		return NULL;
> >  	}
> >  
> > @@ -104,6 +107,7 @@ shm_pool_destroy(struct shm_pool *pool)
> >  {
> >  	munmap(pool->data, pool->size);
> >  	wl_shm_pool_destroy(pool->pool);
> > +	close(pool->fd);
> >  	free(pool);
> >  }
> >  
> > @@ -277,6 +281,11 @@ wl_cursor_theme_load(const char *name, int size, struct wl_shm *shm)
> >  
> >  	theme->pool =
> >  		shm_pool_create(shm, size * size * 4);
> > +	if (!theme->pool) {
> > +		free(theme->name);
> > +		free(theme);
> > +		return NULL;
> > +	}
> >  
> >  	xcursor_load_theme(name, size, load_callback, theme);
> >  
> > -- 
> > 1.7.8.6
> > 



More information about the wayland-devel mailing list