From patchwork Mon Mar 3 19:33:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 22914 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 14DA4BD808 for ; Mon, 3 Mar 2025 19:33:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C276568826; Mon, 3 Mar 2025 20:33:39 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="StD72d9U"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 61F6568779 for ; Mon, 3 Mar 2025 20:33:38 +0100 (CET) Received: from pb-laptop.local (185.221.143.4.nat.pool.zt.hu [185.221.143.4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id BFD67346 for ; Mon, 3 Mar 2025 20:32:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1741030326; bh=FrGbh8uTAEkeMFe8Im5PNDBlhEbS6N7MP8Dgn7H++Lg=; h=From:To:Subject:Date:From; b=StD72d9UATFuCm6kl1n3+K12W9cAHfNuSX/94rR9SjiS6VhfCQq74nCZ2VWeHsDG7 JrcCNothUGNT+0Dak5GwHyw/rmVjVStf3Zkaf8GLPS78duVOwtkXJKT1Xr0ZMvxPWP QbqYXjTl2NwlITCNVWDN0LT0n5YC6/osyQ4cy6Y8= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [PATCH v1] libcamera: ipa_manager: Store `IPAModule`s in `std::unique_ptr` Date: Mon, 3 Mar 2025 20:33:35 +0100 Message-ID: <20250303193335.785606-1-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.48.1 MIME-Version: 1.0 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" Express the ownership more clearly by using a smart pointer type. Signed-off-by: Barnabás Pőcze Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- include/libcamera/internal/ipa_manager.h | 2 +- src/libcamera/ipa_manager.cpp | 18 ++++++------------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/include/libcamera/internal/ipa_manager.h b/include/libcamera/internal/ipa_manager.h index 16dede0c5..e82c25a64 100644 --- a/include/libcamera/internal/ipa_manager.h +++ b/include/libcamera/internal/ipa_manager.h @@ -67,7 +67,7 @@ private: bool isSignatureValid(IPAModule *ipa) const; - std::vector modules_; + std::vector> modules_; #if HAVE_IPA_PUBKEY static const uint8_t publicKeyData_[]; diff --git a/src/libcamera/ipa_manager.cpp b/src/libcamera/ipa_manager.cpp index cfc24d389..830750dcc 100644 --- a/src/libcamera/ipa_manager.cpp +++ b/src/libcamera/ipa_manager.cpp @@ -149,11 +149,7 @@ IPAManager::IPAManager() << "No IPA found in '" IPA_MODULE_DIR "'"; } -IPAManager::~IPAManager() -{ - for (IPAModule *module : modules_) - delete module; -} +IPAManager::~IPAManager() = default; /** * \brief Identify shared library objects within a directory @@ -226,15 +222,13 @@ unsigned int IPAManager::addDir(const char *libDir, unsigned int maxDepth) unsigned int count = 0; for (const std::string &file : files) { - IPAModule *ipaModule = new IPAModule(file); - if (!ipaModule->isValid()) { - delete ipaModule; + auto ipaModule = std::make_unique(file); + if (!ipaModule->isValid()) continue; - } LOG(IPAManager, Debug) << "Loaded IPA module '" << file << "'"; - modules_.push_back(ipaModule); + modules_.push_back(std::move(ipaModule)); count++; } @@ -250,9 +244,9 @@ unsigned int IPAManager::addDir(const char *libDir, unsigned int maxDepth) IPAModule *IPAManager::module(PipelineHandler *pipe, uint32_t minVersion, uint32_t maxVersion) { - for (IPAModule *module : modules_) { + for (const auto &module : modules_) { if (module->match(pipe, minVersion, maxVersion)) - return module; + return module.get(); } return nullptr;