Blob Blame History Raw
From 0d12001c7fb6951fe5cb7c832811340b6f8ef102 Mon Sep 17 00:00:00 2001
From: Erik Kurzinger <ekurzinger@nvidia.com>
Date: Wed, 28 Apr 2021 15:46:41 -0400
Subject: [PATCH] set wl_eglstream fd to -1 after closing

In wlEglCreateStreamAttribHook, if the wl_eglstream handle is a file descriptor
we close the file descriptor after creating the EGLStream.  However, we don't
set the handle to -1 after doing so. This can result in the same file
descriptor being closed a second time in destroy_wl_eglstream_resource when the
client destroys the resource.  By that point, the fd may have been recycled for
some other potentially important purpose, resulting in various kinds of errors
from corruption to crashes.

To avoid this problem, we should set wlStream->handle to -1 after closing the
file descriptor.
---
 src/wayland-eglstream.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/wayland-eglstream.c b/src/wayland-eglstream.c
index fed6bd3..3c40a0d 100644
--- a/src/wayland-eglstream.c
+++ b/src/wayland-eglstream.c
@@ -127,6 +127,7 @@ EGLStreamKHR wlEglCreateStreamAttribHook(EGLDisplay dpy,
 
         /* Clean up */
         close(fd);
+        wlStream->handle = -1;
     }
 #if defined(EGL_NV_stream_attrib) && \
     defined(EGL_NV_stream_remote) && \
-- 
2.31.1