From 181a6a2cead2d260cddb309bcdb02b14f913a745 Mon Sep 17 00:00:00 2001 From: Philipp Zabel Date: Wed, 13 Feb 2019 21:01:06 +0100 Subject: [PATCH] v4l2: do not keep non-capture devices open If VIDIOC_QUERYCAP fails, or V4L2_CAP_VIDEO_CAPTURE is not set, spa_v4l2_open should close the port file descriptor again. --- spa/plugins/v4l2/v4l2-utils.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spa/plugins/v4l2/v4l2-utils.c b/spa/plugins/v4l2/v4l2-utils.c index 34bb2bcda..024f44aa7 100644 --- a/spa/plugins/v4l2/v4l2-utils.c +++ b/spa/plugins/v4l2/v4l2-utils.c @@ -80,6 +80,8 @@ static int spa_v4l2_open(struct impl *this) if (xioctl(port->fd, VIDIOC_QUERYCAP, &port->cap) < 0) { err = errno; spa_log_error(port->log, "QUERYCAP: %m"); + close(port->fd); + port->fd = -1; return -err; } @@ -87,6 +89,8 @@ static int spa_v4l2_open(struct impl *this) ((port->cap.capabilities & V4L2_CAP_DEVICE_CAPS) && (port->cap.device_caps & V4L2_CAP_VIDEO_CAPTURE) == 0)) { spa_log_error(port->log, "v4l2: %s is no video capture device", props->device); + close(port->fd); + port->fd = -1; return -ENODEV; }