mirror of
https://github.com/obsproject/obs-studio.git
synced 2026-08-28 17:42:28 +08:00
linux-v4l2: Fix spurious fd closing
Make sure to use the invalid fd -1 when the output is not opened, and only close valid fds. If fd 0 is closed, then this closes stdin. The second time this happens, some other important fd will have become fd 0, breaking something. This causes random things to break (browser/CEF in reports, but really it could be anything) as the wrong fds get closed.
This commit is contained in:
committed by
Ryan Foster
parent
49708181b5
commit
5533a277e4
@@ -27,7 +27,10 @@ static const char *virtualcam_name(void *unused)
|
||||
static void virtualcam_destroy(void *data)
|
||||
{
|
||||
struct virtualcam_data *vcam = (struct virtualcam_data *)data;
|
||||
close(vcam->device);
|
||||
|
||||
if (vcam->device >= 0)
|
||||
close(vcam->device);
|
||||
|
||||
bfree(data);
|
||||
}
|
||||
|
||||
@@ -133,6 +136,7 @@ static void *virtualcam_create(obs_data_t *settings, obs_output_t *output)
|
||||
{
|
||||
struct virtualcam_data *vcam = (struct virtualcam_data *)bzalloc(sizeof(*vcam));
|
||||
vcam->output = output;
|
||||
vcam->device = -1;
|
||||
|
||||
UNUSED_PARAMETER(settings);
|
||||
return vcam;
|
||||
@@ -256,6 +260,7 @@ static bool try_connect(void *data, const char *device)
|
||||
|
||||
fail_close_device:
|
||||
close(vcam->device);
|
||||
vcam->device = -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -331,6 +336,7 @@ static void virtualcam_stop(void *data, uint64_t ts)
|
||||
}
|
||||
|
||||
close(vcam->device);
|
||||
vcam->device = -1;
|
||||
blog(LOG_INFO, "Virtual camera stopped");
|
||||
|
||||
UNUSED_PARAMETER(ts);
|
||||
|
||||
Reference in New Issue
Block a user