From patchwork Mon Aug 29 08:44:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 17218 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 0D3D0C0DA4 for ; Mon, 29 Aug 2022 08:45:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7B4C561FC6; Mon, 29 Aug 2022 10:45:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1661762701; bh=JOn2Yz0SLXrrVjZ/Ulr08TOR1wHDzS96CPzzwSCVj4g=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=hlAm95Ub+nnwsCeaqhhtprTfPj6Qrn6pMEcXuX8G+UgIai9OxbHEMj32RV0CSe3ZY VjeABGk9xZg5OHlec8QG7VQnPyW22YXbluW+ysblETEq5FOKY/NcpGgvAml/5bC6h1 cwiTGlCi9BmJ53JR1Zbm4tpP3Ji0VR0etRquTYkiKKUkcS4s2HCiGa+pxPb50+9myN fOOxYaCn2qeersx3s7O9TOoPX96V2w+g8eXoHuJ2AALRN/t3LdiTce4zu21OS3+sNx 80IJpJH89ET8NOi5E4eomOBKM9SKgNpMSqZ/urh8gYrDAwXblRaH6b+gmJnQHpn9/f 2MFP4B1sTEDTQ== 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 9240761FBF for ; Mon, 29 Aug 2022 10:44:57 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="jwXIZjv5"; dkim-atps=neutral Received: from deskari.lan (91-158-154-79.elisa-laajakaista.fi [91.158.154.79]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id EBD8A8BD; Mon, 29 Aug 2022 10:44:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1661762697; bh=JOn2Yz0SLXrrVjZ/Ulr08TOR1wHDzS96CPzzwSCVj4g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jwXIZjv5WQ3tATotsDuINWt02IKRq0NHBq6w/devM38N8R4z+U+6K+JhZmx1bTXet vONwDFqP++2c0dfGAU1pNrj/ftZGstdNFdjsBf21MPcuBSUDQ2TB10H4IZrX5jTS39 odysSQUkBBE/4v2vlhXHda7OXnkRd1qq+vVmRqos= To: libcamera-devel , Laurent Pinchart Date: Mon, 29 Aug 2022 11:44:44 +0300 Message-Id: <20220829084445.61585-2-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220829084445.61585-1-tomi.valkeinen@ideasonboard.com> References: <20220829084445.61585-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/2] libcamera: base: log: Fix use of freed name 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: , X-Patchwork-Original-From: Tomi Valkeinen via libcamera-devel From: Tomi Valkeinen Reply-To: Tomi Valkeinen Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" LogCategory just stores the char * that was given to it in the constructor, i.e. it refers to memory "outside" LogCategory. If the LogCategory is defined in a .so that is unloaded, then it leads to the LogCategory pointing to freed memory, causing a crash. Fix this by taking a copy of the name by using a std::string instead of just storing the pointer. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- include/libcamera/base/log.h | 4 ++-- src/libcamera/base/log.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/libcamera/base/log.h b/include/libcamera/base/log.h index 3fc5ced3..8b462767 100644 --- a/include/libcamera/base/log.h +++ b/include/libcamera/base/log.h @@ -31,14 +31,14 @@ class LogCategory public: explicit LogCategory(const char *name); - const char *name() const { return name_; } + const std::string &name() const { return name_; } LogSeverity severity() const { return severity_; } void setSeverity(LogSeverity severity); static const LogCategory &defaultCategory(); private: - const char *name_; + const std::string name_; LogSeverity severity_; }; diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp index 5c359a22..a4a5b452 100644 --- a/src/libcamera/base/log.cpp +++ b/src/libcamera/base/log.cpp @@ -568,7 +568,7 @@ void Logger::logSetLevel(const char *category, const char *level) return; for (LogCategory *c : categories_) { - if (!strcmp(c->name(), category)) { + if (c->name() == category) { c->setSeverity(severity); break; }