[PATCH wayland 4/4] cursor: fix fd leak and a segfault

Pekka Paalanen ppaalanen at gmail.com
Tue Jul 10 03:05:03 PDT 2012


- 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.

Signed-off-by: Pekka Paalanen <ppaalanen at gmail.com>
---
 cursor/wayland-cursor.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/cursor/wayland-cursor.c b/cursor/wayland-cursor.c
index c41860a..186ab6f 100644
--- a/cursor/wayland-cursor.c
+++ b/cursor/wayland-cursor.c
@@ -108,6 +108,7 @@ shm_pool_destroy(struct shm_pool *pool)
 {
 	munmap(pool->data, pool->size);
 	wl_shm_pool_destroy(pool->pool);
+	close(pool->fd);
 	free(pool);
 }
 
@@ -281,6 +282,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