mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hou Tao <houtao@huaweicloud.com>
To: Malaya Kumar Rout <malayarout91@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>, Mykola Lysenko <mykolal@fb.com>,
	Shuah Khan <shuah@kernel.org>, Geliang Tang <geliang@kernel.org>,
	bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] selftests/bpf: close the file descriptor to avoid resource leaks
Date: Tue, 1 Apr 2025 14:46:07 +0800	[thread overview]
Message-ID: <fd481035-5608-6c8e-eb72-65b4ad320d4d@huaweicloud.com> (raw)
In-Reply-To: <20250324064234.853591-1-malayarout91@gmail.com>



On 3/24/2025 2:42 PM, Malaya Kumar Rout wrote:
> Static Analyis for bench_htab_mem.c with cppcheck:error
> tools/testing/selftests/bpf/benchs/bench_htab_mem.c:284:3:
> error: Resource leak: fd [resourceLeak]
> tools/testing/selftests/bpf/prog_tests/sk_assign.c:41:3:
> error: Resource leak: tc [resourceLeak]
>
> fix the issue  by closing the file descriptor (fd & tc) when
> read & fgets operation fails.
>
> Signed-off-by: Malaya Kumar Rout <malayarout91@gmail.com>

Acked-by: Hou Tao <houtao1@huawei.com>

The right subject prefix for the patch should be "[PATCH bpf-next]",
however, it seems there is no need or no reason to respin the patch.
> ---
>  tools/testing/selftests/bpf/benchs/bench_htab_mem.c | 1 +
>  tools/testing/selftests/bpf/prog_tests/sk_assign.c  | 4 +++-
>  2 files changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/bpf/benchs/bench_htab_mem.c b/tools/testing/selftests/bpf/benchs/bench_htab_mem.c
> index 926ee822143e..59746fd2c23a 100644
> --- a/tools/testing/selftests/bpf/benchs/bench_htab_mem.c
> +++ b/tools/testing/selftests/bpf/benchs/bench_htab_mem.c
> @@ -281,6 +281,7 @@ static void htab_mem_read_mem_cgrp_file(const char *name, unsigned long *value)
>  	got = read(fd, buf, sizeof(buf) - 1);
>  	if (got <= 0) {
>  		*value = 0;
> +		close(fd);
>  		return;
>  	}
>  	buf[got] = 0;
> diff --git a/tools/testing/selftests/bpf/prog_tests/sk_assign.c b/tools/testing/selftests/bpf/prog_tests/sk_assign.c
> index 0b9bd1d6f7cc..10a0ab954b8a 100644
> --- a/tools/testing/selftests/bpf/prog_tests/sk_assign.c
> +++ b/tools/testing/selftests/bpf/prog_tests/sk_assign.c
> @@ -37,8 +37,10 @@ configure_stack(void)
>  	tc = popen("tc -V", "r");
>  	if (CHECK_FAIL(!tc))
>  		return false;
> -	if (CHECK_FAIL(!fgets(tc_version, sizeof(tc_version), tc)))
> +	if (CHECK_FAIL(!fgets(tc_version, sizeof(tc_version), tc))) {
> +		pclose(tc);
>  		return false;
> +	}
>  	if (strstr(tc_version, ", libbpf "))
>  		prog = "test_sk_assign_libbpf.bpf.o";
>  	else


  reply	other threads:[~2025-04-01  6:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-24  6:42 Malaya Kumar Rout
2025-04-01  6:46 ` Hou Tao [this message]
2025-04-04 15:52 ` Andrii Nakryiko
2025-04-05  5:59   ` malaya kumar rout
2025-04-07  1:36     ` Hou Tao
2025-04-07  3:40       ` malaya kumar rout
2025-04-07 10:01         ` Re:[PATCH v2] " Malaya Kumar Rout
2025-04-08  2:30           ` [PATCH " Hou Tao
2025-04-08 18:31             ` Re:[PATCH RESEND bpf-next " Malaya Kumar Rout
2025-04-09 23:27               ` [PATCH " Andrii Nakryiko
2025-04-09 23:30                 ` Alexei Starovoitov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fd481035-5608-6c8e-eb72-65b4ad320d4d@huaweicloud.com \
    --to=houtao@huaweicloud.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=geliang@kernel.org \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=malayarout91@gmail.com \
    --cc=martin.lau@linux.dev \
    --cc=mykolal@fb.com \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®