[libcamera-devel] [PATCH v3 23/33] cam: Use std::unique_ptr<> to manage CameraManager
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Thu Jul 15 23:14:49 CEST 2021
Store the CameraManager instance in a unique_ptr to simplify memory
management and avoid leaks.
Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
---
src/cam/main.cpp | 13 +++----------
1 file changed, 3 insertions(+), 10 deletions(-)
diff --git a/src/cam/main.cpp b/src/cam/main.cpp
index 8ed5e841a1e9..2ef26353e712 100644
--- a/src/cam/main.cpp
+++ b/src/cam/main.cpp
@@ -25,7 +25,6 @@ class CamApp
{
public:
CamApp();
- ~CamApp();
static CamApp *instance();
@@ -49,8 +48,8 @@ private:
static CamApp *app_;
OptionsParser::Options options_;
- CameraManager *cm_;
+ std::unique_ptr<CameraManager> cm_;
std::unique_ptr<CameraSession> session_;
EventLoop loop_;
@@ -59,16 +58,10 @@ private:
CamApp *CamApp::app_ = nullptr;
CamApp::CamApp()
- : cm_(nullptr)
{
CamApp::app_ = this;
}
-CamApp::~CamApp()
-{
- delete cm_;
-}
-
CamApp *CamApp::instance()
{
return CamApp::app_;
@@ -82,7 +75,7 @@ int CamApp::init(int argc, char **argv)
if (ret < 0)
return ret;
- cm_ = new CameraManager();
+ cm_ = std::make_unique<CameraManager>();
ret = cm_->start();
if (ret) {
@@ -92,7 +85,7 @@ int CamApp::init(int argc, char **argv)
}
if (options_.isSet(OptCamera)) {
- session_ = std::make_unique<CameraSession>(cm_, options_);
+ session_ = std::make_unique<CameraSession>(cm_.get(), options_);
if (!session_->isValid()) {
std::cout << "Failed to create camera session" << std::endl;
cleanup();
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list