Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp457346lqo; Fri, 10 May 2024 05:23:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUNzU7G1Va1xzoPETgwvumUjJ7VvUumZESUSvMlj+Sp5ceocd74uzbWcEnsJzncStvpExEfO8W/SyNZ/jpe08G1TCxJtXvnx5SFEAyJyQ== X-Google-Smtp-Source: AGHT+IH/mEbV4pAOeNrMRXgDkkvWseMsX3Y3Co+23K6YIgrdswS4sz90qqPTejc3CfzYKYs0HU+A X-Received: by 2002:a17:90a:be12:b0:2b2:7855:da05 with SMTP id 98e67ed59e1d1-2b6cc780521mr2558435a91.26.1715343835479; Fri, 10 May 2024 05:23:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715343835; cv=pass; d=google.com; s=arc-20160816; b=f/QRcizFDKe4ikZscEMWtgKBsHRZoL6HehR6N33/pTVxvfoc59vxzDhYQ/rcLB4/3Q zHwEjRIs1NZW3L9UAbMQehT6ei8jGVaLZsvghMQBiQcfN+2ZmuyJ6fApAWrj99lA3i3h QMx5cUH8SjOp+AV3UubRJLK8WNSxslfNiJKPx52F+Ah8jdqYXAIdc5LZ2jQQgHXSpGE3 LmVCSQE/M2eL8PmWl2QK6lAKaX8Q3VzwEGiSESetILydDJEu6LMVYWB+ZC72q3QjIZhN zswmHizVtkw1MBdAlIlt+1T1qlr1/iziy6r+1FF5W/7lt8xuoxeMmsCdFbk3HHmW6W27 0klA== 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=xZ213klW9bdz0yUpL12nFiGeW9tocETynyBLxv+frdo=; fh=uo5u2TQK/HQlhydMwGLjBAnuDwaLxndJ/cgWTjIagS8=; b=NitjhHQXUmJI/jil38f0CWWyM0gytzzcTl/vb3k+QmTOMZqn3+gXjvNGN4S8Y8jYSa 6r7ks3YLPNPFfoqS89nbXW2wKHkXtiEGyWs017urwpe6NpHsA2i4pDCwJuJfM/hKT5cI o0+RZMEDBDZhYz++ChYQK/dWg+gJRGIBNt+kUGAyeuA97Fen6X5/ps2EQRBwgiRrMbmE X6etS/ZZn7cgy+qjGX7W/sJedMvodK5NZPlL2h4bXr6ZRc4MLnNrr0QihzYzFhOOdXhn e4Lg34VEJMimUHeWI7vDA4WX5OyhpShxZELKbSz/tEfEpT7ZxzfFK8O55/C7DR5P/EaX zp/g==; 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-4484-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-4484-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2b670e34472si3659770a91.34.2024.05.10.05.23.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 05:23:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-4484-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=hadess.net); spf=pass (google.com: domain of linux-bluetooth+bounces-4484-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-4484-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 A166B287029 for ; Fri, 10 May 2024 12:15:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 96A5617106E; Fri, 10 May 2024 12:14:19 +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 911BC16F90D 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=1715343259; cv=none; b=DAUvD4OmtsoEpdj/Ygmo64fSL+DVJ/jnP56x8uI+W6AInXSIfZeqdgwhOrGe8uLCcmAiqBpJ//5+90QomQzsR+cSWuTcYGwJoHBW4K14rG3JfQzBv0bl6UXE07wFhcuT5ZwkjwgtlGLNAZCqU5sKexGxx7zFCE5wqntAuq1hQNk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715343259; c=relaxed/simple; bh=vFe5qKmQHRVEE4cES7AAibKqsLuZAYq13Rek/uW306Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hFdRCTlmCFp29asH7zpX9YhCx0jPalHRMMdlHMTKh/dyMjnkhIE+xMkJFfVYXFoPt/umk62eT1mkPZgwA8WkLZmXh5kVWkr/55cKDXpp5szxZqRSJZGiL06T1QOMIt09GQM27ckz9T8IoCAHGx3++Jy0xVBTjcIrTfQuyMk5nE4= 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 2213060015; Fri, 10 May 2024 12:14:01 +0000 (UTC) From: Bastien Nocera To: linux-bluetooth@vger.kernel.org Cc: Bastien Nocera Subject: [BlueZ v2 18/20] monitor: Work-around memory leak warning Date: Fri, 10 May 2024 14:10:28 +0200 Message-ID: <20240510121355.3241456-19-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 Work-around this warning by making the so pointer global. Error: RESOURCE_LEAK (CWE-772): [#def29] [important] bluez-5.75/monitor/jlink.c:87:3: alloc_fn: Storage is returned from allocation function "dlopen". bluez-5.75/monitor/jlink.c:87:3: var_assign: Assigning: "so" = storage returned from "dlopen(jlink_so_name[i], 1)". bluez-5.75/monitor/jlink.c:95:2: noescape: Resource "so" is not freed or pointed-to in "dlsym". bluez-5.75/monitor/jlink.c:96:2: noescape: Resource "so" is not freed or pointed-to in "dlsym". bluez-5.75/monitor/jlink.c:97:2: noescape: Resource "so" is not freed or pointed-to in "dlsym". bluez-5.75/monitor/jlink.c:98:2: noescape: Resource "so" is not freed or pointed-to in "dlsym". bluez-5.75/monitor/jlink.c:99:2: noescape: Resource "so" is not freed or pointed-to in "dlsym". bluez-5.75/monitor/jlink.c:100:2: noescape: Resource "so" is not freed or pointed-to in "dlsym". bluez-5.75/monitor/jlink.c:101:2: noescape: Resource "so" is not freed or pointed-to in "dlsym". bluez-5.75/monitor/jlink.c:102:2: noescape: Resource "so" is not freed or pointed-to in "dlsym". bluez-5.75/monitor/jlink.c:103:2: noescape: Resource "so" is not freed or pointed-to in "dlsym". bluez-5.75/monitor/jlink.c:104:2: noescape: Resource "so" is not freed or pointed-to in "dlsym". bluez-5.75/monitor/jlink.c:116:2: leaked_storage: Variable "so" going out of scope leaks the storage it points to. 114| 115| /* don't dlclose(so) here cause symbols from it are in use now */ 116|-> return 0; 117| } 118| --- monitor/jlink.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/monitor/jlink.c b/monitor/jlink.c index f9d4037f4cdf..e08cc87139c9 100644 --- a/monitor/jlink.c +++ b/monitor/jlink.c @@ -47,6 +47,7 @@ struct rtt_desc { }; static struct rtt_desc rtt_desc; +static void *so = NULL; typedef int (*jlink_emu_selectbyusbsn_func) (unsigned int sn); typedef int (*jlink_open_func) (void); @@ -80,7 +81,6 @@ static struct jlink jlink; int jlink_init(void) { - void *so; unsigned int i; for (i = 0; i < NELEM(jlink_so_name); i++) { @@ -109,6 +109,7 @@ int jlink_init(void) !jlink.emu_getproductname || !jlink.rtterminal_control || !jlink.rtterminal_read) { dlclose(so); + so = NULL; return -EIO; } -- 2.44.0