Module: Mesa
Branch: main
Commit: 1950481d08d706e8f23780f7a44802a6ed5f5c52
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=1950481d08d706e8f23780f7a44802a6ed5f5c52

Author: Ian Douglas Scott <[email protected]>
Date:   Mon Aug 28 16:18:01 2023 -0700

egl/wayland: Don't segfault if `create_wl_buffer` returns `NULL`

Normally, this shouldn't fail, but it has various cases where it returns
`NULL`. Without this change, it would result in a segfault when
`wl_buffer_add_listener` is called.

This instead makes `EGLSwapBuffers` return a `EGL_BAD_ALLOC` error.

The other place `create_wl_buffer` is called already checks the return
value, and the Vulkan WSI code doesn't seem to have an issue like this.

Signed-off-by: Ian Douglas Scott <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24915>

---

 src/egl/drivers/dri2/platform_wayland.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/egl/drivers/dri2/platform_wayland.c 
b/src/egl/drivers/dri2/platform_wayland.c
index dac98e8f6bc..6507e635299 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -1602,6 +1602,9 @@ dri2_wl_swap_buffers_with_damage(_EGLDisplay *disp, 
_EGLSurface *draw,
       dri2_surf->current->wl_buffer =
          create_wl_buffer(dri2_dpy, dri2_surf, image);
 
+      if (dri2_surf->current->wl_buffer == NULL)
+         return _eglError(EGL_BAD_ALLOC, "dri2_swap_buffers");
+
       dri2_surf->current->wl_release = false;
 
       wl_buffer_add_listener(dri2_surf->current->wl_buffer, 
&wl_buffer_listener,

Reply via email to