From 8e8e1f7a945f4eb209cfe6b9a0b6c9b4a8a1c163 Mon Sep 17 00:00:00 2001 From: Christian Meissl Date: Mon, 31 Jan 2022 17:50:42 +0100 Subject: [PATCH] fix dma buffer fd leak --- src/backend/allocator/gbm.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/backend/allocator/gbm.rs b/src/backend/allocator/gbm.rs index f5bf9fd..10fc07e 100644 --- a/src/backend/allocator/gbm.rs +++ b/src/backend/allocator/gbm.rs @@ -96,14 +96,19 @@ impl AsDmabuf for GbmBuffer { return Err(GbmConvertError::UnsupportedBuffer); //TODO } - if self.fd()? == 0 { + // Make sure to only call fd once as each call will create + // a new file descriptor which has to be closed + let fd = self.fd()?; + + // gbm_bo_get_fd returns -1 if an error occurs + if fd == -1 { return Err(GbmConvertError::InvalidFD); } let mut builder = Dmabuf::builder_from_buffer(self, DmabufFlags::empty()); for idx in 0..planes { builder.add_plane( - self.fd()?, + fd, idx as u32, self.offset(idx)?, self.stride_for_plane(idx)?,