From f6a23b8e7e0d0089453367876a9f90abfeb2b394 Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Sat, 26 Apr 2025 19:38:51 +0300 Subject: dmabuffb: dup() the fds Use dup() on the given fds, and take ownership of them. close() at destructor. Fixes: #46 --- kms++/src/dmabufframebuffer.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'kms++/src') diff --git a/kms++/src/dmabufframebuffer.cpp b/kms++/src/dmabufframebuffer.cpp index f303799..3d5b133 100644 --- a/kms++/src/dmabufframebuffer.cpp +++ b/kms++/src/dmabufframebuffer.cpp @@ -39,9 +39,9 @@ DmabufFramebuffer::DmabufFramebuffer(Card& card, uint32_t width, uint32_t height for (int i = 0; i < format_info.num_planes; ++i) { FramebufferPlane& plane = m_planes.at(i); - plane.prime_fd = fds[i]; + plane.prime_fd = dup(fds[i]); - r = drmPrimeFDToHandle(card.fd(), fds[i], &plane.handle); + r = drmPrimeFDToHandle(card.fd(), plane.prime_fd, &plane.handle); if (r) throw invalid_argument(string("drmPrimeFDToHandle: ") + strerror(errno)); @@ -76,6 +76,16 @@ DmabufFramebuffer::DmabufFramebuffer(Card& card, uint32_t width, uint32_t height DmabufFramebuffer::~DmabufFramebuffer() { drmModeRmFB(card().fd(), id()); + + for (uint i = 0; i < m_num_planes; ++i) { + FramebufferPlane& plane = m_planes.at(i); + + if (plane.map) + munmap(plane.map, plane.size); + + if (plane.prime_fd >= 0) + ::close(plane.prime_fd); + } } uint8_t* DmabufFramebuffer::map(unsigned plane) -- cgit v1.2.3