Merge pull request #487 from cmeissl/fix/dma_buffer_fd_leak

fix dma buffer fd leak
This commit is contained in:
Victoria Brekenfeld 2022-01-31 18:54:18 +01:00 committed by GitHub
commit d04a999bf8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -96,14 +96,19 @@ impl<T> AsDmabuf for GbmBuffer<T> {
return Err(GbmConvertError::UnsupportedBuffer); //TODO 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); return Err(GbmConvertError::InvalidFD);
} }
let mut builder = Dmabuf::builder_from_buffer(self, DmabufFlags::empty()); let mut builder = Dmabuf::builder_from_buffer(self, DmabufFlags::empty());
for idx in 0..planes { for idx in 0..planes {
builder.add_plane( builder.add_plane(
self.fd()?, fd,
idx as u32, idx as u32,
self.offset(idx)?, self.offset(idx)?,
self.stride_for_plane(idx)?, self.stride_for_plane(idx)?,