summaryrefslogtreecommitdiff
path: root/src/cam
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-07-06 07:37:14 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-07-22 17:13:48 +0300
commit033cac7f6df5a3bd671eccf03f57103897f11c97 (patch)
tree9e0acccf2526114a3bc338a49996e8c967750819 /src/cam
parent8519df23a9b8fbc4d845787bc4ad443792736347 (diff)
cam: Use std::unique_ptr<> to manage CameraManager
Store the CameraManager instance in a unique_ptr to simplify memory management and avoid leaks. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'src/cam')
-rw-r--r--src/cam/main.cpp13
1 files changed, 3 insertions, 10 deletions
diff --git a/src/cam/main.cpp b/src/cam/main.cpp
index 8ed5e841..2ef26353 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();