cam: Use the common cleanup function on failure

The different error paths in init() are out of sync. Instead of fixing
them switch to using the cleanup() function which does the right thing
for all cases.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
This commit is contained in:
Niklas Söderlund 2020-08-04 00:49:42 +02:00
parent 375fef72f8
commit 1074604c9e

View file

@ -107,22 +107,23 @@ int CamApp::init(int argc, char **argv)
std::cout << "Camera " std::cout << "Camera "
<< std::string(options_[OptCamera]) << std::string(options_[OptCamera])
<< " not found" << std::endl; << " not found" << std::endl;
cm_->stop(); cleanup();
return -ENODEV; return -ENODEV;
} }
if (camera_->acquire()) { if (camera_->acquire()) {
std::cout << "Failed to acquire camera" << std::endl; std::cout << "Failed to acquire camera" << std::endl;
camera_.reset(); cleanup();
cm_->stop();
return -EINVAL; return -EINVAL;
} }
std::cout << "Using camera " << camera_->name() << std::endl; std::cout << "Using camera " << camera_->name() << std::endl;
ret = prepareConfig(); ret = prepareConfig();
if (ret) if (ret) {
cleanup();
return ret; return ret;
}
} }
if (options_.isSet(OptMonitor)) { if (options_.isSet(OptMonitor)) {