1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-02-04 06:08:26 +02:00

lavd/v4l2: do not clobber the context FD in v4l2_get_device_list()

The FD opened here is local to the loop iteration, there is no reason to
store it in the context. Since read_header() may have already been
called, this may ovewrite an existing valid FD.
This commit is contained in:
Anton Khirnov 2021-11-25 11:27:02 +01:00
parent 007819a5bc
commit e1151fbf22

View File

@ -1033,16 +1033,17 @@ static int v4l2_get_device_list(AVFormatContext *ctx, AVDeviceInfoList *device_l
return ret; return ret;
} }
while ((entry = readdir(dir))) { while ((entry = readdir(dir))) {
int fd = -1;
char device_name[256]; char device_name[256];
if (!v4l2_is_v4l_dev(entry->d_name)) if (!v4l2_is_v4l_dev(entry->d_name))
continue; continue;
snprintf(device_name, sizeof(device_name), "/dev/%s", entry->d_name); snprintf(device_name, sizeof(device_name), "/dev/%s", entry->d_name);
if ((s->fd = device_open(ctx, device_name)) < 0) if ((fd = device_open(ctx, device_name)) < 0)
continue; continue;
if (v4l2_ioctl(s->fd, VIDIOC_QUERYCAP, &cap) < 0) { if (v4l2_ioctl(fd, VIDIOC_QUERYCAP, &cap) < 0) {
ret = AVERROR(errno); ret = AVERROR(errno);
av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYCAP): %s\n", av_err2str(ret)); av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYCAP): %s\n", av_err2str(ret));
goto fail; goto fail;
@ -1064,8 +1065,7 @@ static int v4l2_get_device_list(AVFormatContext *ctx, AVDeviceInfoList *device_l
&device_list->nb_devices, device)) < 0) &device_list->nb_devices, device)) < 0)
goto fail; goto fail;
v4l2_close(s->fd); v4l2_close(fd);
s->fd = -1;
continue; continue;
fail: fail:
@ -1074,9 +1074,7 @@ static int v4l2_get_device_list(AVFormatContext *ctx, AVDeviceInfoList *device_l
av_freep(&device->device_description); av_freep(&device->device_description);
av_freep(&device); av_freep(&device);
} }
if (s->fd >= 0) v4l2_close(fd);
v4l2_close(s->fd);
s->fd = -1;
break; break;
} }
closedir(dir); closedir(dir);