From 91b5a003a5f48df2920e628c1f0a0bd02f476280 Mon Sep 17 00:00:00 2001 From: Michel Dänzer Date: Thu, 3 Oct 2024 12:33:56 +0200 Subject: xwayland/glamor/gbm: Don't close fence_fd after xwl_glamor_wait_fence eglCreateSyncKHR takes ownership of the file descriptor. Noticed by inspection. While we're at it, move the fence_fd declaration to the scope where it's used. Last but not least, close the fd in xwl_glamor_wait_fence when bailing before calling eglCreateSyncKHR, and document that it takes ownership. Part-of: --- hw/xwayland/xwayland-glamor-gbm.c | 7 +++---- hw/xwayland/xwayland-glamor.c | 5 ++++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/hw/xwayland/xwayland-glamor-gbm.c b/hw/xwayland/xwayland-glamor-gbm.c index 92241bd1e..45f18a47c 100644 --- a/hw/xwayland/xwayland-glamor-gbm.c +++ b/hw/xwayland/xwayland-glamor-gbm.c @@ -1516,16 +1516,15 @@ xwl_glamor_gbm_wait_syncpts(PixmapPtr pixmap) #ifdef DRI3 struct xwl_screen *xwl_screen = xwl_screen_get(pixmap->drawable.pScreen); struct xwl_pixmap *xwl_pixmap = xwl_pixmap_get(pixmap); - int fence_fd; if (!xwl_screen->glamor || !xwl_pixmap) return; if (xwl_pixmap->syncobj) { - fence_fd = xwl_pixmap->syncobj->export_fence(xwl_pixmap->syncobj, - xwl_pixmap->timeline_point); + int fence_fd = xwl_pixmap->syncobj->export_fence(xwl_pixmap->syncobj, + xwl_pixmap->timeline_point); + xwl_glamor_wait_fence(xwl_screen, fence_fd); - close(fence_fd); } #endif /* DRI3 */ } diff --git a/hw/xwayland/xwayland-glamor.c b/hw/xwayland/xwayland-glamor.c index c3aa483ff..6618a0a34 100644 --- a/hw/xwayland/xwayland-glamor.c +++ b/hw/xwayland/xwayland-glamor.c @@ -198,14 +198,17 @@ xwl_glamor_get_fence(struct xwl_screen *xwl_screen) return fence_fd; } +/* Takes ownership of fence_fd, specifically eglCreateSyncKHR does */ void xwl_glamor_wait_fence(struct xwl_screen *xwl_screen, int fence_fd) { EGLint attribs[3]; EGLSyncKHR sync; - if (!xwl_screen->glamor) + if (!xwl_screen->glamor) { + close(fence_fd); return; + } xwl_glamor_egl_make_current(xwl_screen); -- cgit v1.2.3