From patchwork Tue Feb 25 17:36:22 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: 22878 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 E05D5BDB1C for ; Tue, 25 Feb 2025 17:36:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9BEF66873C; Tue, 25 Feb 2025 18:36:29 +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="Y5MWTuey"; dkim-atps=neutral Received: from mail-10630.protonmail.ch (mail-10630.protonmail.ch [79.135.106.30]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3667368725 for ; Tue, 25 Feb 2025 18:36:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1740504986; x=1740764186; bh=Ub0xATXAZom6FXNmQZ3DrfsR/hgEl3RCjniWHGgBM7Q=; h=Date:To:From:Cc: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=Y5MWTueyqNKkgW7mEGagWxHvMdfWqZUkv8b1Eqe0fWh9oDlVWL6sxKxk7LtC8R5eM lX8XFyL009rxTxtyltnFtYnwenWTusIN0B1tjjTufa0ynaF07UQ9ZQboKwAAPso5ih ow+Bf+QqvPFJJCn/fXww96J/QuVmKI35w1y8UhutGQv91mb9KTbMuRZS1p8s+KR+cp d5nAWQnv+invpmh7q/ZU4zHcD4NTHdvprURZ/J0Q1Mmf9jjWAwAlR8jhkj4eVyaGd/ 0UbMl2VfFh+fPkjyrwNxkyJxWqlvmGfvzrUPbHsWkkb9yqDb/ZPBl9HAQEsEu2Kymg DWUH3sSME5PDA== Date: Tue, 25 Feb 2025 17:36:22 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Cc: Laurent Pinchart Subject: [PATCH v4 8/8] libcamera: base: log: Avoid manual `LogCategory` deletion Message-ID: <20250225173531.2595922-9-pobrn@protonmail.com> In-Reply-To: <20250225173531.2595922-1-pobrn@protonmail.com> References: <20250225173531.2595922-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: 985a84bd74ef8a2b5ae65e0368901862f7a0a068 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 Reviewed-by: Jacopo Mondi --- 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 155355f0c..72614eeb1 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::shared_ptr 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 *categoryName = category->name().c_str(); for (const auto &[pattern, severity] : levels_) {