[libcamera-devel] [PATCH 20/30] cam: Use std::unique_ptr<> to manager CameraManager
Kieran Bingham
kieran.bingham at ideasonboard.com
Mon Jul 12 17:45:04 CEST 2021
Hi Laurent,
$SUBJECT: s/manager/manage/
On 07/07/2021 03:19, Laurent Pinchart wrote:
> 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>
> ---
> 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)
\o/
> {
> CamApp::app_ = this;
> }
>
> -CamApp::~CamApp()
> -{
> - delete cm_;
\o/
Gotta love these wins.
Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
> -}
> -
> 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();
>
More information about the libcamera-devel
mailing list