Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp457282lqo; Fri, 10 May 2024 05:23:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX80mPX5fiFRn1ijrH/k9lc2XsBJY1KNLoyVO+59OvUbgFiJvPmyt7R6uDy99yHQABNoPWPPhGuewrVXmMXDOD/CaYVhX3bNjURB/1O+Q== X-Google-Smtp-Source: AGHT+IHhAEuAm1tIGZmr0yevk5YtYBU7Aj6eSxxMI+HPTQci/F5zkGlXzXW26Q5gWLmkjAHjPA3V X-Received: by 2002:a05:6a20:5a95:b0:1af:6428:1812 with SMTP id adf61e73a8af0-1afd1417a8cmr7836512637.4.1715343828323; Fri, 10 May 2024 05:23:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715343828; cv=pass; d=google.com; s=arc-20160816; b=G+c70UlZmfgtSRFt0GAjIp1QWYlUESlALz5DcGxQRrPQRXifA/DRl1JQtt5YaD8d1m 9SRBs0Ul7QauUge7OVCheQB0+fFHCmcTleoWDr7caObwuI63ljdSz9Uc/adDHtv/Mzye Dvc0X1Lmr4cAxHeBmOZG35sazlEqiTEtKkX2eNtMyV3GlN6KveLZVXGv/5lgOA2YMBsK o3E8jQ+0pkBr1lytWgwRtNSrABlXnc+HSdIq+5ZlQBH2qu2y6kgY9+gOxWvetF0n/Pla 5wL34mVaEXInFFUQGE3NhsrS9EufwJSkU/d/iNhice855zp8HpLH4UkG+Pm8pep/wczL 4xBg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=GL+7WerSHSjE3Ufbl7WUJc9F2VDuy/7xTZDiQyDedqw=; fh=uo5u2TQK/HQlhydMwGLjBAnuDwaLxndJ/cgWTjIagS8=; b=xSUcZ/Tixrqzj1pGBAIISduQSqoDxnoG/thZMnURa4gC7obx9rFtBPYkEx7fg9Eo8B zZXVQ3PBk3QHg6vwt8mORVI3JzTo2efeXsLpAxqpWQE8wjJjPW9HKBZp1l7RE7lPCra5 zUJ23uvWGTXVXx46cURrsNiDIMPpIVJRfaQ/OC4+2kUxiEix6r0jo3FQJSY4KnUar4ma Y+YcbWDJ5xLuitx2n6xA6qq1C0uQaf6AnxDkkDRkM4Zyo5MReeKnd8NFr3HiCJAd9xcw 5j4xKv/mHuSZHsHehCqKpBF7j2JUH4UZfqRP7az2pMr4LDLcFTWOfJCEBERZr5LAZVXT Eoxg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=hadess.net); spf=pass (google.com: domain of linux-bluetooth+bounces-4482-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-4482-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-63412c3691csi3460459a12.723.2024.05.10.05.23.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 05:23:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-4482-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=hadess.net); spf=pass (google.com: domain of linux-bluetooth+bounces-4482-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-4482-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 54A8F286CE9 for ; Fri, 10 May 2024 12:15:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C23F41708BC; Fri, 10 May 2024 12:14:18 +0000 (UTC) X-Original-To: linux-bluetooth@vger.kernel.org Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 44F6A16F26E for ; Fri, 10 May 2024 12:14:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.195 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715343258; cv=none; b=sg/Oaptg5TNYOVxjRWkMOqBtAADql0j4zrcqGUIuoqg7yKQpqhaJ+Gxvbwou/DTtTaEI+qmJZ9SE2zGcHY4B1Sgmp1Nem9MgWf7N1HKcQ6Kg20gBT1BsYwpOABla9DWkoL10pTHjbZ1qv7lP5isBiFgvUY7nfUW0AqqPhHoC/+M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715343258; c=relaxed/simple; bh=vEdzOFOfj6cU3KZYSAw5Qn4GRuDd16JZXvr2cYFm7/c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uiLqOPM9OfHXTmH2LMi56h6h7fvzNCf1Ao4ZvUspL3jiRx/FsHdAQFIOlwn9tmX9RlPoPQsvIxdMUDcZilsCtaGa/vvTRkvgHa/5m1hufopIiP7NC6o57uzwRQKJ++wHG2pOQp6fn67JwRq5UikgEESQDOnUNf5nBuf/E2z8wPM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hadess.net; spf=pass smtp.mailfrom=hadess.net; arc=none smtp.client-ip=217.70.183.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hadess.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hadess.net Received: by mail.gandi.net (Postfix) with ESMTPSA id AC08560019; Fri, 10 May 2024 12:14:01 +0000 (UTC) From: Bastien Nocera To: linux-bluetooth@vger.kernel.org Cc: Bastien Nocera Subject: [BlueZ v2 20/20] main: Simplify variable assignment Date: Fri, 10 May 2024 14:10:30 +0200 Message-ID: <20240510121355.3241456-21-hadess@hadess.net> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240510121355.3241456-1-hadess@hadess.net> References: <20240510121355.3241456-1-hadess@hadess.net> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-GND-Sasl: hadess@hadess.net Error: RESOURCE_LEAK (CWE-772): [#def39] [important] bluez-5.75/src/main.c:425:2: alloc_fn: Storage is returned from allocation function "g_key_file_get_string". bluez-5.75/src/main.c:425:2: var_assign: Assigning: "tmp" = storage returned from "g_key_file_get_string(config, group, key, &err)". bluez-5.75/src/main.c:433:2: noescape: Assuming resource "tmp" is not freed or pointed-to as ellipsis argument to "btd_debug". bluez-5.75/src/main.c:440:2: leaked_storage: Variable "tmp" going out of scope leaks the storage it points to. 438| } 439| 440|-> return true; 441| } 442| --- src/main.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main.c b/src/main.c index ac840d684f6d..a31740179941 100644 --- a/src/main.c +++ b/src/main.c @@ -420,9 +420,10 @@ static bool parse_config_string(GKeyFile *config, const char *group, const char *key, char **val) { GError *err = NULL; - char *tmp; - tmp = g_key_file_get_string(config, group, key, &err); + g_return_val_if_fail(val, false); + + *val = g_key_file_get_string(config, group, key, &err); if (err) { if (err->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND) DBG("%s", err->message); @@ -430,12 +431,7 @@ static bool parse_config_string(GKeyFile *config, const char *group, return false; } - DBG("%s.%s = %s", group, key, tmp); - - if (val) { - g_free(*val); - *val = tmp; - } + DBG("%s.%s = %s", group, key, *val); return true; } -- 2.44.0