From 1950481d08d706e8f23780f7a44802a6ed5f5c52 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Mon, 28 Aug 2023 16:18:01 -0700 Subject: [PATCH] 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 Part-of: --- 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,