From 881f820fdf33279186b42eeb48820dea88018bd9 Mon Sep 17 00:00:00 2001 From: Aaron Boxer Date: Thu, 26 Jan 2023 14:18:17 -0500 Subject: [PATCH] vo_dmabuf_wayland: close file handles when surface export fails file handles may still be opened despite failure --- video/out/vo_dmabuf_wayland.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/video/out/vo_dmabuf_wayland.c b/video/out/vo_dmabuf_wayland.c index 81fc15fd56..565fe50a97 100644 --- a/video/out/vo_dmabuf_wayland.c +++ b/video/out/vo_dmabuf_wayland.c @@ -74,6 +74,12 @@ static uintptr_t vaapi_key_provider(struct mp_image *src) return va_surface_id(src); } +static void close_file_descriptors(VADRMPRIMESurfaceDescriptor desc) +{ + for (int i = 0; i < desc.num_objects; i++) + close(desc.objects[i].fd); +} + /* va-api dmabuf importer */ static bool vaapi_dmabuf_importer(struct mp_image *src, struct wlbuf_pool_entry* entry, struct zwp_linux_buffer_params_v1 *params) @@ -89,6 +95,8 @@ static bool vaapi_dmabuf_importer(struct mp_image *src, struct wlbuf_pool_entry* /* invalid surface warning => composed layers not supported */ if (status == VA_STATUS_ERROR_INVALID_SURFACE) MP_VERBOSE(entry->vo, "vaExportSurfaceHandle: composed layers not supported.\n"); + close_file_descriptors(desc); + return false; } bool success = false; @@ -108,8 +116,7 @@ static bool vaapi_dmabuf_importer(struct mp_image *src, struct wlbuf_pool_entry* success = true; done: - for (int i = 0; i < desc.num_objects; i++) - close(desc.objects[i].fd); + close_file_descriptors(desc); return success; }