From 7f93f8cd97c857af0348d8a5621e30c044bb5b51 Mon Sep 17 00:00:00 2001 From: Joseph Coffland Date: Sat, 15 Sep 2018 15:34:18 -0700 Subject: [PATCH] Fix deallocation bug which causes Python to exit/crash if the device fails to load. See https://github.com/gebart/python-v4l2capture/issues/13 --- v4l2capture.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/v4l2capture.c b/v4l2capture.c index 0b266aa..2e74142 100644 --- a/v4l2capture.c +++ b/v4l2capture.c @@ -133,15 +133,14 @@ static int Video_device_init(Video_device *self, PyObject *args, return -1; } - int fd = v4l2_open(device_path, O_RDWR | O_NONBLOCK); + self->fd = v4l2_open(device_path, O_RDWR | O_NONBLOCK); - if(fd < 0) + if(self->fd < 0) { PyErr_SetFromErrnoWithFilename(PyExc_IOError, (char *)device_path); return -1; } - self->fd = fd; self->buffers = NULL; return 0; }