Skip to content

Commit 5533a27

Browse files
hoshinolinaRytoEX
authored andcommitted
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.
1 parent 4970818 commit 5533a27

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

plugins/linux-v4l2/v4l2-output.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ static const char *virtualcam_name(void *unused)
2727
static void virtualcam_destroy(void *data)
2828
{
2929
struct virtualcam_data *vcam = (struct virtualcam_data *)data;
30-
close(vcam->device);
30+
31+
if (vcam->device >= 0)
32+
close(vcam->device);
33+
3134
bfree(data);
3235
}
3336

@@ -133,6 +136,7 @@ static void *virtualcam_create(obs_data_t *settings, obs_output_t *output)
133136
{
134137
struct virtualcam_data *vcam = (struct virtualcam_data *)bzalloc(sizeof(*vcam));
135138
vcam->output = output;
139+
vcam->device = -1;
136140

137141
UNUSED_PARAMETER(settings);
138142
return vcam;
@@ -256,6 +260,7 @@ static bool try_connect(void *data, const char *device)
256260

257261
fail_close_device:
258262
close(vcam->device);
263+
vcam->device = -1;
259264
return false;
260265
}
261266

@@ -331,6 +336,7 @@ static void virtualcam_stop(void *data, uint64_t ts)
331336
}
332337

333338
close(vcam->device);
339+
vcam->device = -1;
334340
blog(LOG_INFO, "Virtual camera stopped");
335341

336342
UNUSED_PARAMETER(ts);

0 commit comments

Comments
 (0)