Blob Blame History Raw
From 95224f0f92bc516983038a6326fba041cdef6e75 Mon Sep 17 00:00:00 2001
From: Olivier Fourdan <ofourdan@redhat.com>
Date: Mon, 29 Mar 2021 14:22:56 +0200
Subject: [PATCH xserver 06/27] xwayland/eglstream: Check buffer creation
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

EGLStream wl_eglstream_display_create_stream() may fail, yet Xwayland
would try to attach the buffer which may cause a fatal Wayland protocol
error raised by the compositor.

Check if the buffer creation worked, and fail gracefully otherwise (like
wayland-eglsurface does).

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Martin Peres <martin.peres@mupuf.org>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
https://gitlab.freedesktop.org/xorg/xserver/-/issues/1156
(cherry picked from commit 4f0889e98306d30a37aba0fadb1fd3790c13205a)
---
 hw/xwayland/xwayland-glamor-eglstream.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/hw/xwayland/xwayland-glamor-eglstream.c b/hw/xwayland/xwayland-glamor-eglstream.c
index 17295f3bd..c6e17bf8b 100644
--- a/hw/xwayland/xwayland-glamor-eglstream.c
+++ b/hw/xwayland/xwayland-glamor-eglstream.c
@@ -548,6 +548,10 @@ xwl_eglstream_create_pending_stream(struct xwl_screen *xwl_screen,
                                            stream_fd,
                                            WL_EGLSTREAM_HANDLE_TYPE_FD,
                                            &stream_attribs);
+    if (!xwl_pixmap->buffer) {
+        ErrorF("eglstream: Failed to create buffer\n");
+        goto fail;
+    }
 
     wl_buffer_add_listener(xwl_pixmap->buffer,
                            &xwl_eglstream_buffer_release_listener,
@@ -562,7 +566,9 @@ xwl_eglstream_create_pending_stream(struct xwl_screen *xwl_screen,
 
     xwl_eglstream_queue_pending_stream(xwl_screen, window, pixmap);
 
-    close(stream_fd);
+fail:
+    if (stream_fd >= 0)
+        close(stream_fd);
 }
 
 static Bool
-- 
2.31.1