summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNaushir Patuck <naush@raspberrypi.com>2020-05-14 09:40:03 +0100
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-05-18 14:02:32 +0300
commit353fc4c223225f32176f9fc35a832d633486aa0d (patch)
tree18df3aee24b43e7b66dccfec92d03c7167efcafe /src
parentaa7e7175c7c7407ef0d6400055dfec5086b31f3b (diff)
libcamera: v4l2_videodevice: Fix dangling file descriptor
The FileDescriptor constructor used in V4L2VideoDevice::exportDmabufFd() creates a duplicate of the fd to store in the object. The original fd returned by the VIDIOC_EXPBUF ioctl was never closed, and left dangling. This would cause out of memory conditions if the camera stream was repeatedly started and stopped. This change closes the original fd explicitly, fixing the leak. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src')
-rw-r--r--src/libcamera/v4l2_videodevice.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
index d35596bd..fbe55bc6 100644
--- a/src/libcamera/v4l2_videodevice.cpp
+++ b/src/libcamera/v4l2_videodevice.cpp
@@ -1276,7 +1276,14 @@ FileDescriptor V4L2VideoDevice::exportDmabufFd(unsigned int index,
return FileDescriptor();
}
- return FileDescriptor(expbuf.fd);
+ FileDescriptor fd(expbuf.fd);
+ /*
+ * FileDescriptor takes a duplicate of fd, so we must close the
+ * original here, otherwise it will be left dangling.
+ */
+ ::close(expbuf.fd);
+
+ return fd;
}
/**