From e8f27c2a7940620b019a8b030d1443b253fa8b6e Mon Sep 17 00:00:00 2001 From: Stefan Hoffmeister Date: Mon, 12 Sep 2022 15:15:16 +0200 Subject: [PATCH] linux-v4l2: Fix resource leak on device open error path --- plugins/linux-v4l2/v4l2-output.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plugins/linux-v4l2/v4l2-output.c b/plugins/linux-v4l2/v4l2-output.c index fa4a4005e..d0b6a532c 100644 --- a/plugins/linux-v4l2/v4l2-output.c +++ b/plugins/linux-v4l2/v4l2-output.c @@ -128,12 +128,12 @@ static bool try_connect(void *data, const char *device) return false; if (ioctl(vcam->device, VIDIOC_QUERYCAP, &capability) < 0) - return false; + goto fail_close_device; format.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; if (ioctl(vcam->device, VIDIOC_G_FMT, &format) < 0) - return false; + goto fail_close_device; struct obs_video_info ovi; obs_get_video_info(&ovi); @@ -146,7 +146,7 @@ static bool try_connect(void *data, const char *device) parm.parm.output.timeperframe.denominator = ovi.fps_num; if (ioctl(vcam->device, VIDIOC_S_PARM, &parm) < 0) - return false; + goto fail_close_device; format.fmt.pix.width = width; format.fmt.pix.height = height; @@ -154,7 +154,7 @@ static bool try_connect(void *data, const char *device) format.fmt.pix.sizeimage = vcam->frame_size; if (ioctl(vcam->device, VIDIOC_S_FMT, &format) < 0) - return false; + goto fail_close_device; struct video_scale_info vsi = {0}; vsi.format = VIDEO_FORMAT_YUY2; @@ -166,6 +166,10 @@ static bool try_connect(void *data, const char *device) obs_output_begin_data_capture(vcam->output, 0); return true; + +fail_close_device: + close(vcam->device); + return false; } static int scanfilter(const struct dirent *entry)