From patchwork Fri Aug 26 11:39:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 17204 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 66678C0DA4 for ; Fri, 26 Aug 2022 11:39:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4E47B61FBB; Fri, 26 Aug 2022 13:39:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1661513985; bh=DQfpMcbNtUoBdFmgnTbLvJ38yNa23qiAAEaj7/AVmwo=; 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=HjJIP1nPhcDpA9tc09mKlgJLc33MRQ3hAaxl//4Mf/o+cbx/q4Gw9b4AUtMdpBXsH ISOhkxxyMejlq7ee7xpSYs2boVuIxC6Dj2iI+IkWs7tB3/322GO+P++dAhOw/HMHJy N6a60LCJwkZlGxtr0EiM0LCw+gStvFo1EnmPmES4DSMwc8WJF1cgzWqG1Mec4vyOzE gRy/jFNh6rDDGZhsDWrFQghIA6R5eZvPdb7P4uHEJokmO97ct8Pdpgv02HKWocGwGk UEOv7efXIWt3IY8dE7vfCUipSPSgL29xTQQurP/xsGQ2otLN4rKR3Fqc08qCnmXgk1 KuXuU2SVtNO/w== 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 4A74E61FBB for ; Fri, 26 Aug 2022 13:39:43 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="hEQQoZj0"; 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 B70363F1; Fri, 26 Aug 2022 13:39:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1661513982; bh=DQfpMcbNtUoBdFmgnTbLvJ38yNa23qiAAEaj7/AVmwo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hEQQoZj05JY1/Us71QKqwwGONBQNkVdZDt2XUbKk9GX9UIVrHCpbIKhwH2kc8I5Ua pwTmLYziouNfD/MaJFAKZdbPZ8jDZ6SDFEvwcC/LtYF7Bpd+qe9a8J0QH+ITaCe0mf NlntZPO7lRzFuZyEsIABMT6vWD3uN813KS9v1OcA= To: libcamera-devel Date: Fri, 26 Aug 2022 14:39:30 +0300 Message-Id: <20220826113931.59323-2-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220826113931.59323-1-tomi.valkeinen@ideasonboard.com> References: <20220826113931.59323-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 --- 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; }