From 84c55d6efca59592616b3ef32ae4875be444dbe4 Mon Sep 17 00:00:00 2001 From: loki Date: Sun, 6 Jun 2021 20:57:42 +0200 Subject: [PATCH] Fix file descriptor leak --- assets/sunshine.conf | 3 ++- sunshine/platform/linux/vaapi.cpp | 14 +++++++++++++- sunshine/utility.h | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/assets/sunshine.conf b/assets/sunshine.conf index 7a67c87b..db9692d1 100644 --- a/assets/sunshine.conf +++ b/assets/sunshine.conf @@ -247,4 +247,5 @@ # To set the initial state of flags -0 and -1 to on, set the following flags: # flags = 01 # -# See: sunshine --help for all options under the header: flags \ No newline at end of file +# See: sunshine --help for all options under the header: flags +adapter_name=/dev/dri/renderD129 \ No newline at end of file diff --git a/sunshine/platform/linux/vaapi.cpp b/sunshine/platform/linux/vaapi.cpp index fe144694..8faa29dc 100644 --- a/sunshine/platform/linux/vaapi.cpp +++ b/sunshine/platform/linux/vaapi.cpp @@ -581,6 +581,11 @@ struct nv12_img_t { gl::tex_t tex; gl::frame_buf_t buf; + + static constexpr std::size_t num_fds = + sizeof(va::DRMPRIMESurfaceDescriptor::objects) / sizeof(va::DRMPRIMESurfaceDescriptor::objects[0]); + + std::array fds; }; KITTY_USING_MOVE_T(nv12_t, nv12_img_t, , { @@ -626,6 +631,12 @@ public: return std::nullopt; } + // Keep track of file descriptors + std::array fds; + for(int x = 0; x < prime.num_objects; ++x) { + fds[x] = prime.objects[x].fd; + } + int img_attr_planes[2][13] { { EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_R8, EGL_WIDTH, (int)prime.width, @@ -649,7 +660,8 @@ public: eglCreateImageKHR(display.get(), EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, nullptr, img_attr_planes[0]), eglCreateImageKHR(display.get(), EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, nullptr, img_attr_planes[1]), gl::tex_t::make(2), - gl::frame_buf_t::make(2) + gl::frame_buf_t::make(2), + std::move(fds) }; if(!nv12->r8 || !nv12->bg88) { diff --git a/sunshine/utility.h b/sunshine/utility.h index 41c4b59c..82643e1d 100644 --- a/sunshine/utility.h +++ b/sunshine/utility.h @@ -33,7 +33,7 @@ struct argument_type { typedef U type; }; move_t(Args &&...args) : el { std::forward(args)... } {} \ move_t(const move_t &) = delete; \ \ - explicit move_t(move_t &&other) : el { std::move(other.el) } { \ + move_t(move_t &&other) noexcept : el { std::move(other.el) } { \ other.el = element_type { init_val }; \ } \ \