From 24ca846a27d3b5f3e371dcd039df6ee74dd113c1 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 5 Jul 2021 07:19:00 +0300 Subject: cam: camera_session: Use std::unique_ptr<> to manage class members Store the BufferWriter and FrameBufferAllocator pointers in std::unique_ptr<> instances to simplify memory management and avoid leaks. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/cam/camera_session.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src/cam/camera_session.cpp') diff --git a/src/cam/camera_session.cpp b/src/cam/camera_session.cpp index b1200e60..1fb7c1b6 100644 --- a/src/cam/camera_session.cpp +++ b/src/cam/camera_session.cpp @@ -20,9 +20,8 @@ using namespace libcamera; CameraSession::CameraSession(std::shared_ptr camera, CameraConfiguration *config) - : camera_(camera), config_(config), writer_(nullptr), last_(0), - queueCount_(0), captureCount_(0), captureLimit_(0), - printMetadata_(false), allocator_(nullptr) + : camera_(camera), config_(config), last_(0), queueCount_(0), + captureCount_(0), captureLimit_(0), printMetadata_(false) { } @@ -56,12 +55,12 @@ int CameraSession::start(const OptionsParser::Options &options) if (options.isSet(OptFile)) { if (!options[OptFile].toString().empty()) - writer_ = new BufferWriter(options[OptFile]); + writer_ = std::make_unique(options[OptFile]); else - writer_ = new BufferWriter(); + writer_ = std::make_unique(); } - allocator_ = new FrameBufferAllocator(camera_); + allocator_ = std::make_unique(camera_); return startCapture(); } @@ -72,12 +71,11 @@ void CameraSession::stop() if (ret) std::cout << "Failed to stop capture" << std::endl; - delete writer_; - writer_ = nullptr; + writer_.reset(); requests_.clear(); - delete allocator_; + allocator_.reset(); } int CameraSession::startCapture() -- cgit v1.2.1