summaryrefslogtreecommitdiff
path: root/include/libcamera/file_descriptor.h
AgeCommit message (Collapse)Author
2020-05-19libcamera: file_descriptor: Implement move semantics for constructorLaurent Pinchart
The FileDescriptor class, when constructed from a numerical file descriptor, duplicates the file descriptor and takes ownership of the copy. The caller has to close the original file descriptor manually if needed. This is inefficient as the dup() and close() calls could be avoided, but can also lead to resource leakage, as recently shown by commit 353fc4c22322 ("libcamera: v4l2_videodevice: Fix dangling file descriptor"). In an attempt to solve this problem, implement move semantics for the FileDescriptor constructor. The constructor taking a numerical file descriptor is split in two variants: - A "fd copy" constructor that takes a const lvalue reference to a numerical file descriptor and duplicates it (corresponding to the current behaviour). - A "fd move" constructor that takes a rvalue reference to a numerical file descriptor and takes ownership of it. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
2020-01-12libcamera: Add FileDescriptor to help pass numerical fds aroundNiklas Söderlund
Add a helper to make it easier to pass file descriptors around. The helper class duplicates the fd which decouples it from the original fd which could be closed by its owner while the new FileDescriptor remains valid. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>