Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp151682lqo; Thu, 16 May 2024 02:04:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU4Y9cE/R2SgWR8vEx3XbSNrwFDFgcSnw0+1g6lY6taGUDEbpYMFMdJnvL3qGbJh22FPQN5pJwYOs1DvhfCAPXccErloMDD2/VB5QCDlA== X-Google-Smtp-Source: AGHT+IGGh7056YZaqiZOmFByDrO/dp2lNLeSTfQpLo8NrWCXsBvJ2GXWPs6x9nFvLpCvBpEhLWuv X-Received: by 2002:a17:907:3ac4:b0:a5c:dd34:25ec with SMTP id a640c23a62f3a-a5cdd342677mr163689266b.4.1715850247316; Thu, 16 May 2024 02:04:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715850247; cv=pass; d=google.com; s=arc-20160816; b=CUG9ubfC74xnGRmqCDItxSDcOgK4zx3xLIVEXGxv4yH8YgYVpzCf3T/0dOEA7u3UE5 bZ1wlmEhoA87Ey/2YnxjbjxQ5bvlabE7ENjvPGBzXaXA6m5HcAEh1+8uxIY56CfOu/Iu ZhmbtQ205ES3ko9wPC3WXdY3HUMyjL1Q8pFgX6zmuN+Q5wJ/V9yl2xk2CBIi37RSlflc POn7FNlr8SVPNb9EtOPXcahcGEDmLgyAzoaD5uPWxEuTDLta3hQqQqgoHzeukEbweOM1 UkfCH2f+SYxSVrTc4t5Y5q4VIjfM0JFuqyfUGkk8SzDm3zz7PnSVU0oU//jbdI1q4KJ5 Li3w== 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=RanSMt5MMho0FjNY9p6wzY4V8lRv5zOoxK44axR7aVw=; fh=uo5u2TQK/HQlhydMwGLjBAnuDwaLxndJ/cgWTjIagS8=; b=MjUWjQ7b7hpDW1FlvE56AfUjYT08PFDwHwlMZnisfmuPvOys156r2cLNmTW3dWW5fQ r4ibA6jAV8MytuOPUQwMr0AYLGe6lI2MeUR8viChr5UttQMIkqDzhpKrEdEfbfxE0XEV tCDGur1/DjUSXIzS9QOTcnW9MXmt+sqs09KE3Vj8H8SYIb1GdbvY7KhKpXEaw/oW1apy qvH5K2iwO4x+4+/UZnPbJbZvf/nTyS5ozhKJG4/ZxhYzrZFJ0Bi2HIf+4jISCq9zGAl0 8AmmrlPJIdE8Tp/h7ptnO4ufiaJHFbMbWhgCyMQN0NPFBFzjKNO1Jdc9qpF/qZWhe7JN qU7w==; 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-4688-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-4688-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17b21c5csi849157066b.351.2024.05.16.02.04.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 02:04:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-4688-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=hadess.net); spf=pass (google.com: domain of linux-bluetooth+bounces-4688-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-4688-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 088221F23614 for ; Thu, 16 May 2024 09:04:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9A3E614373F; Thu, 16 May 2024 09:03:50 +0000 (UTC) X-Original-To: linux-bluetooth@vger.kernel.org Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 32938142E94 for ; Thu, 16 May 2024 09:03:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715850230; cv=none; b=C5JE6EucNTatLTbNQDnREZ1HpmcbEh56Iw3MV1pCu3Rtv/K2ksNIrh8SS9o+Vgb0J6H5mgAyFwblEwU6Ta+wm5vVLJk1pPW53E4TmdT6hrXNUihIF1ansu1J12P2SZgEsG5kDE0wzg4nCilh50T22YP/1+erjvxU5XnZh9eOYQ4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715850230; c=relaxed/simple; bh=gH4GoI2T/j0yiZYxFEnxRxCV+ZsffcBK9aBmxKu8sJk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=khfXItFMgJYcp43u0rMwiGOEPjbFjhuWw0wKpCxcTiZl/FeEcGa2s1vcWtPOiM/t4kCOeWHQPno55xAfWOF0F3/FfVbeaTaJuZO8R+W5RMk2o2qviZ4gimKzw3Uiz1WBaWLVdO1IwBLibE2LYukJwSWHF/h+9w1XvK3beLpSDxY= 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.197 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 466171C000D; Thu, 16 May 2024 09:03:41 +0000 (UTC) From: Bastien Nocera To: linux-bluetooth@vger.kernel.org Cc: Bastien Nocera Subject: [BlueZ 01/15] main: Simplify variable assignment Date: Thu, 16 May 2024 11:03:05 +0200 Message-ID: <20240516090340.61417-2-hadess@hadess.net> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240516090340.61417-1-hadess@hadess.net> References: <20240516090340.61417-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 | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main.c b/src/main.c index ac840d684f6d..f6369a20d879 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; } @@ -1005,7 +1001,12 @@ static void parse_secure_conns(GKeyFile *config) static void parse_general(GKeyFile *config) { - parse_config_string(config, "General", "Name", &btd_opts.name); + char *str = NULL; + + if (parse_config_string(config, "General", "Name", &str)) { + g_free(btd_opts.name); + btd_opts.name = str; + } parse_config_hex(config, "General", "Class", &btd_opts.class); parse_config_u32(config, "General", "DiscoverableTimeout", &btd_opts.discovto, -- 2.44.0