From ab16fcc8dbdff5779d09c306741a2e508fb9bd67 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sat, 29 Sep 2018 22:59:00 +0200 Subject: [PATCH] Wayland: Check for buffer creation failure This prevents unusable decoration objects from being created, and invalid cursors from being returned to the user. --- src/wl_window.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/wl_window.c b/src/wl_window.c index 93bb1729..b23dc746 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -186,7 +186,7 @@ static struct wl_buffer* createShmBuffer(const GLFWimage* image) _glfwInputError(GLFW_PLATFORM_ERROR, "Wayland: Creating a buffer file for %d B failed: %m", length); - return GLFW_FALSE; + return NULL; } data = mmap(NULL, length, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); @@ -195,7 +195,7 @@ static struct wl_buffer* createShmBuffer(const GLFWimage* image) _glfwInputError(GLFW_PLATFORM_ERROR, "Wayland: mmap failed: %m"); close(fd); - return GLFW_FALSE; + return NULL; } pool = wl_shm_create_pool(_glfw.wl.shm, fd, length); @@ -265,6 +265,8 @@ static void createDecorations(_GLFWwindow* window) if (!window->wl.decorations.buffer) window->wl.decorations.buffer = createShmBuffer(&image); + if (!window->wl.decorations.buffer) + return; createDecoration(&window->wl.decorations.top, window->wl.surface, window->wl.decorations.buffer, opaque, @@ -1308,6 +1310,9 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor, int xhot, int yhot) { cursor->wl.buffer = createShmBuffer(image); + if (!cursor->wl.buffer) + return GLFW_FALSE; + cursor->wl.width = image->width; cursor->wl.height = image->height; cursor->wl.xhot = xhot;