libcamera: handle failure gracefully

Don't try to access NULL pointers
This commit is contained in:
Wim Taymans 2021-09-30 12:54:29 +02:00
parent f8817b4394
commit d71a10b7fa
3 changed files with 9 additions and 8 deletions

View file

@ -210,10 +210,10 @@ impl_init(const struct spa_handle_factory *factory,
SPA_DEVICE_CHANGE_MASK_PROPS;
this->info.flags = 0;
if(this->dev.camera == NULL) {
if(this->dev.camera == NULL)
this->dev.camera = (LibCamera*)newLibCamera();
if(this->dev.camera != NULL)
libcamera_set_log(this->dev.camera, this->dev.log);
}
return 0;
}

View file

@ -994,10 +994,10 @@ impl_init(const struct spa_handle_factory *factory,
port->dev.log = this->log;
port->dev.fd = -1;
if(port->dev.camera == NULL) {
if(port->dev.camera == NULL)
port->dev.camera = (LibCamera*)newLibCamera();
if(port->dev.camera != NULL)
libcamera_set_log(port->dev.camera, port->dev.log);
}
if (info && (str = spa_dict_lookup(info, SPA_KEY_API_LIBCAMERA_PATH))) {
strncpy(this->props.device, str, 63);

View file

@ -540,6 +540,7 @@ extern "C" {
}
void LibCamera::close() {
if (this->cam_)
this->cam_->release();
}
@ -775,6 +776,9 @@ extern "C" {
std::unique_ptr<CameraManager> cm = std::make_unique<CameraManager>();
LibCamera* camera = new LibCamera();
pthread_mutexattr_init(&attr);
pthread_mutex_init(&camera->lock, &attr);
ret = cm->start();
if (ret) {
deleteLibCamera(camera);
@ -794,9 +798,6 @@ extern "C" {
return nullptr;
}
pthread_mutexattr_init(&attr);
pthread_mutex_init(&camera->lock, &attr);
camera->ring_buffer_init();
return camera;