From patchwork Mon Feb 17 18:55:10 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: 22808 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 0CC13C3200 for ; Mon, 17 Feb 2025 18:55:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A955468698; Mon, 17 Feb 2025 19:55:15 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=protonmail.com header.i=@protonmail.com header.b="WMewOK2l"; dkim-atps=neutral Received: from mail-40133.protonmail.ch (mail-40133.protonmail.ch [185.70.40.133]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 98DF368697 for ; Mon, 17 Feb 2025 19:55:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1739818512; x=1740077712; bh=IKmqx1SXJwpufJa0slW3yC48eFAvkOWt4qFhcYH/H+g=; h=Date:To:From:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=WMewOK2lrcwyfaC6Q0wOX92dmRLGt93KxjOHnmySye0Z/kGdEQN+2RJouFjoXIdg/ jxuslklxlcQQaqAlXa5BClHr9DNIarxk6Q02EM2PYHfoKe8+Wtb1KEfKZsWclcipZD q6r4WY1px3hlnI5/yi3P5R9o3uFExu4IEXOAFVpha0Lgjh9nfXTGl9AQ2RZSdcgg3J WnsgE5GD4JE9qt+Qo8r8w9nZXWD8/jUdtHj74ptDE0fD7K6vUUP4lv+KYMd3248dgg mMnqk39qxNAwgPIKwa8A5I/lxv2xXblzlk/hMJAVObXUWg2ohKLrc56ucbp+E/vWyF 25ddKoox9Zx9A== Date: Mon, 17 Feb 2025 18:55:10 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 8/8] libcamera: base: log: Avoid manual `LogCategory` deletion Message-ID: <20250217185433.306833-9-pobrn@protonmail.com> In-Reply-To: <20250217185433.306833-1-pobrn@protonmail.com> References: <20250217185433.306833-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: 56ff5397914f1c91dccec090acdcd645003fd2c7 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" Wrap the `LogCategory` pointers in `std::unique_ptr` to avoid the need for manual deletion in the destructor. Signed-off-by: Barnabás Pőcze Reviewed-by: Laurent Pinchart --- src/libcamera/base/log.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp index fd6c11716..e05ffc1c4 100644 --- a/src/libcamera/base/log.cpp +++ b/src/libcamera/base/log.cpp @@ -322,7 +322,7 @@ private: static bool destroyed_; Mutex mutex_; - std::vector categories_ LIBCAMERA_TSA_GUARDED_BY(mutex_); + std::vector> categories_ LIBCAMERA_TSA_GUARDED_BY(mutex_); std::list> levels_; std::atomic> output_; @@ -439,9 +439,6 @@ void logSetLevel(const char *category, const char *level) Logger::~Logger() { destroyed_ = true; - - for (LogCategory *category : categories_) - delete category; } /** @@ -574,7 +571,7 @@ void Logger::logSetLevel(const char *category, const char *level) MutexLocker locker(mutex_); - for (LogCategory *c : categories_) { + for (const auto &c : categories_) { if (c->name() == category) { c->setSeverity(severity); break; @@ -718,12 +715,12 @@ LogCategory *Logger::findOrCreateCategory(std::string_view name) { MutexLocker locker(mutex_); - for (LogCategory *category : categories_) { + for (const auto &category : categories_) { if (category->name() == name) - return category; + return category.get(); } - LogCategory *category = categories_.emplace_back(new LogCategory(name)); + LogCategory *category = categories_.emplace_back(std::unique_ptr(new LogCategory(name))).get(); const char *name_cstr = category->name().c_str(); for (const auto &[pattern, severity] : levels_) {