Skip to content

Commit

Permalink
Close DmaHeap when closing DmaAllocator
Browse files Browse the repository at this point in the history
The DmaHeap file descriptor wasn't being closed when the DmaAllocator
was closed, resulting in a leak of file descriptors.

Signed-off-by: William Vinnicombe <[email protected]>
  • Loading branch information
will-v-pi committed Feb 20, 2024
1 parent e6c6d92 commit 9050cc2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions picamera2/allocators/dmaallocator.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ def close(self):
os.close(fd)
self.frame_buffers = {}
self.open_fds = []
if self.dmaHeap is not None:
self.dmaHeap.close()

def __del__(self):
self.close()
Expand Down
1 change: 1 addition & 0 deletions picamera2/allocators/persistent_allocator.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def deallocate(self, buffer_key=None):
buffer_key = self.buffer_key

tmp = super().__new__(DmaAllocator)
tmp.dmaHeap = None

(tmp.open_fds, tmp.libcamera_fds, tmp.frame_buffers,
tmp.mapped_buffers, tmp.mapped_buffers_used) = self.buffer_dict[buffer_key]
Expand Down
3 changes: 3 additions & 0 deletions picamera2/dma_heap.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,6 @@ def alloc(self, name, size) -> UniqueFD:
return UniqueFD()

return allocFd

def close(self):
os.close(self.__dmaHeapHandle.get())

0 comments on commit 9050cc2

Please sign in to comment.