From patchwork Mon Jul 12 21:56:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 12932 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id CD77CC3226 for ; Mon, 12 Jul 2021 21:57:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 59FCC68548; Mon, 12 Jul 2021 23:57:54 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Jgpd4Peh"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 745A76852B for ; Mon, 12 Jul 2021 23:57:42 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 197913F1 for ; Mon, 12 Jul 2021 23:57:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1626127062; bh=bUtsSy4UE3H6V43iaM72VWdZ+Y8/Y9xnZbYxwPkH0K8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Jgpd4PehLO/vjQkkEDAy+iwipFBLGELk0r8x9RJPBaAz+HB1QPKQ4+7ejlN5lWJ15 /biVyu2KL36ve1/JhcVQggZhzWFZqtj0dSqnHw1lab4hOCavK+9mxjTW30ZfrbOumo X5n+jcTt7xEMGAU9rktVy2yGAmzAGarReIUEDxzI= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 13 Jul 2021 00:56:35 +0300 Message-Id: <20210712215645.30478-21-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210712215645.30478-1-laurent.pinchart@ideasonboard.com> References: <20210712215645.30478-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 20/30] cam: Use std::unique_ptr<> to manage CameraManager X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Store the CameraManager instance in a unique_ptr to simplify memory management and avoid leaks. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- 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 cm_; std::unique_ptr 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(); ret = cm_->start(); if (ret) { @@ -92,7 +85,7 @@ int CamApp::init(int argc, char **argv) } if (options_.isSet(OptCamera)) { - session_ = std::make_unique(cm_, options_); + session_ = std::make_unique(cm_.get(), options_); if (!session_->isValid()) { std::cout << "Failed to create camera session" << std::endl; cleanup();