[libcamera-devel] [PATCH] cam: Use the common cleanup function on failure

Niklas Söderlund niklas.soderlund at ragnatech.se
Tue Aug 4 01:03:28 CEST 2020


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

Signed-off-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>
---
 src/cam/main.cpp | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/cam/main.cpp b/src/cam/main.cpp
index ec59e9eaf1176a94..6761d63801bd19af 100644
--- a/src/cam/main.cpp
+++ b/src/cam/main.cpp
@@ -107,22 +107,23 @@ int CamApp::init(int argc, char **argv)
 			std::cout << "Camera "
 				  << std::string(options_[OptCamera])
 				  << " not found" << std::endl;
-			cm_->stop();
+			cleanup();
 			return -ENODEV;
 		}
 
 		if (camera_->acquire()) {
 			std::cout << "Failed to acquire camera" << std::endl;
-			camera_.reset();
-			cm_->stop();
+			cleanup();
 			return -EINVAL;
 		}
 
 		std::cout << "Using camera " << camera_->name() << std::endl;
 
 		ret = prepareConfig();
-		if (ret)
+		if (ret) {
+			cleanup();
 			return ret;
+		}
 	}
 
 	if (options_.isSet(OptMonitor)) {
-- 
2.28.0



More information about the libcamera-devel mailing list