[{"id":18128,"web_url":"https://patchwork.libcamera.org/comment/18128/","msgid":"<8b9df4d6-eeab-3807-7511-8de9c44f175e@ideasonboard.com>","date":"2021-07-12T15:27:30","subject":"Re: [libcamera-devel] [PATCH 16/30] cam: camera_session: Use\n\tstd::unique_ptr<> to manage class members","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"On 07/07/2021 03:19, Laurent Pinchart wrote:\n> Store the BufferWriter and FrameBufferAllocator pointers in\n> std::unique_ptr<> instances to simplify memory management and avoid\n> leaks.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n\n> ---\n>  src/cam/camera_session.cpp | 16 +++++++---------\n>  src/cam/camera_session.h   |  4 ++--\n>  2 files changed, 9 insertions(+), 11 deletions(-)\n> \n> diff --git a/src/cam/camera_session.cpp b/src/cam/camera_session.cpp\n> index b1200e60329c..1fb7c1b6ad5d 100644\n> --- a/src/cam/camera_session.cpp\n> +++ b/src/cam/camera_session.cpp\n> @@ -20,9 +20,8 @@ using namespace libcamera;\n>  \n>  CameraSession::CameraSession(std::shared_ptr<Camera> camera,\n>  \t\t\t     CameraConfiguration *config)\n> -\t: camera_(camera), config_(config), writer_(nullptr), last_(0),\n> -\t  queueCount_(0), captureCount_(0), captureLimit_(0),\n> -\t  printMetadata_(false), allocator_(nullptr)\n> +\t: camera_(camera), config_(config), last_(0), queueCount_(0),\n> +\t  captureCount_(0), captureLimit_(0), printMetadata_(false)\n>  {\n>  }\n>  \n> @@ -56,12 +55,12 @@ int CameraSession::start(const OptionsParser::Options &options)\n>  \n>  \tif (options.isSet(OptFile)) {\n>  \t\tif (!options[OptFile].toString().empty())\n> -\t\t\twriter_ = new BufferWriter(options[OptFile]);\n> +\t\t\twriter_ = std::make_unique<BufferWriter>(options[OptFile]);\n>  \t\telse\n> -\t\t\twriter_ = new BufferWriter();\n> +\t\t\twriter_ = std::make_unique<BufferWriter>();\n>  \t}\n>  \n> -\tallocator_ = new FrameBufferAllocator(camera_);\n> +\tallocator_ = std::make_unique<FrameBufferAllocator>(camera_);\n>  \n>  \treturn startCapture();\n>  }\n> @@ -72,12 +71,11 @@ void CameraSession::stop()\n>  \tif (ret)\n>  \t\tstd::cout << \"Failed to stop capture\" << std::endl;\n>  \n> -\tdelete writer_;\n> -\twriter_ = nullptr;\n> +\twriter_.reset();\n>  \n>  \trequests_.clear();\n>  \n> -\tdelete allocator_;\n> +\tallocator_.reset();\n>  }\n>  \n>  int CameraSession::startCapture()\n> diff --git a/src/cam/camera_session.h b/src/cam/camera_session.h\n> index 5131cfd48b4e..31e8d6db01d9 100644\n> --- a/src/cam/camera_session.h\n> +++ b/src/cam/camera_session.h\n> @@ -44,7 +44,7 @@ private:\n>  \tlibcamera::CameraConfiguration *config_;\n>  \n>  \tstd::map<const libcamera::Stream *, std::string> streamName_;\n> -\tBufferWriter *writer_;\n> +\tstd::unique_ptr<BufferWriter> writer_;\n>  \tuint64_t last_;\n>  \n>  \tunsigned int queueCount_;\n> @@ -52,7 +52,7 @@ private:\n>  \tunsigned int captureLimit_;\n>  \tbool printMetadata_;\n>  \n> -\tlibcamera::FrameBufferAllocator *allocator_;\n> +\tstd::unique_ptr<libcamera::FrameBufferAllocator> allocator_;\n>  \tstd::vector<std::unique_ptr<libcamera::Request>> requests_;\n>  };\n>  \n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 26E0CC3225\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 12 Jul 2021 15:27:35 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7333E68524;\n\tMon, 12 Jul 2021 17:27:34 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9EFF468513\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 Jul 2021 17:27:33 +0200 (CEST)","from [192.168.0.20]\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 34B2DCC;\n\tMon, 12 Jul 2021 17:27:33 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"l9LXoDVn\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1626103653;\n\tbh=mGA4ickBz0B2UKfwcfsaqPWNw1WI/BE2r7yXbssGqQc=;\n\th=Subject:To:References:From:Date:In-Reply-To:From;\n\tb=l9LXoDVni5NbrivZZeZOXGWOIIfAQbmZ7I4YDGVsGQuWCAivMoGrb+TKbXXJVxFeW\n\twtGWN5g4iU/JWDBaGaUx0W58sJtL1yNUBNV4JISBVf8uAq4pUsJAyGm/98cnn2napx\n\tfN6Y8kmyRcUhOuQ4llwVo0i16auwz1xF8C/2i/70=","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20210707021941.20804-1-laurent.pinchart@ideasonboard.com>\n\t<20210707021941.20804-17-laurent.pinchart@ideasonboard.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<8b9df4d6-eeab-3807-7511-8de9c44f175e@ideasonboard.com>","Date":"Mon, 12 Jul 2021 16:27:30 +0100","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101\n\tThunderbird/78.11.0","MIME-Version":"1.0","In-Reply-To":"<20210707021941.20804-17-laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-GB","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH 16/30] cam: camera_session: Use\n\tstd::unique_ptr<> to manage class members","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]