From: Ingo Molnar <mingo@kernel.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Malaya Kumar Rout <malayarout91@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Shuah Khan <shuah@kernel.org>,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH] selftests/x86/lam: fix memory leak and resource leak in lam.c
Date: Tue, 25 Mar 2025 10:29:50 +0100 [thread overview]
Message-ID: <Z-J3jlYcocf_w4M_@gmail.com> (raw)
In-Reply-To: <20250324125108.GH14944@noisy.programming.kicks-ass.net>
* Peter Zijlstra <peterz@infradead.org> wrote:
> On Mon, Mar 24, 2025 at 06:17:50PM +0530, Malaya Kumar Rout wrote:
> > Static Analyis for bench_htab_mem.c with cppcheck:error
> > tools/testing/selftests/x86/lam.c:585:3:
> > error: Resource leak: file_fd [resourceLeak]
> > tools/testing/selftests/x86/lam.c:593:3:
> > error: Resource leak: file_fd [resourceLeak]
> > tools/testing/selftests/x86/lam.c:600:3:
> > error: Memory leak: fi [memleak]
> > tools/testing/selftests/x86/lam.c:1066:2:
> > error: Resource leak: fd [resourceLeak]
> >
> > fix the issue by closing the file descriptors and
> > releasing the allocated memory.
> >
>
> But but but, doesn't the program just exit on any of those 'errors'
> anyway?
>
> That is, iirc this is a single shot program.
While that's true, still proper cleanup of resources is a good practice
- and in more complicated tools it's useful to fix even these
semi-false-positives, to make sure other warnings don't get missed.
Having said that, the error/cleanup control flow here doesn't look
overly clean here to begin with, so I'd suggest fixing that (with goto
labels or such) - which would fix the file_fd 'leak' as a happy side
effect.
Thanks,
Ingo
next prev parent reply other threads:[~2025-03-25 9:29 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-24 12:47 [PATCH] selftests/x86/lam: fix memory leak and resource leak in lam.c Malaya Kumar Rout
2025-03-24 12:51 ` Peter Zijlstra
2025-03-25 9:29 ` Ingo Molnar [this message]
2025-03-25 9:56 ` malaya kumar rout
2025-03-25 13:25 ` Malaya Kumar Rout
2025-04-07 10:44 ` [PATCH v2] selftests/x86/lam: fix resource leak in do_uring() and allocate_dsa_pasid() Malaya Kumar Rout
2025-04-07 18:20 ` Ingo Molnar
2025-04-07 19:34 ` [PATCH v3] " Malaya Kumar Rout
2025-04-08 8:09 ` Ingo Molnar
2025-04-08 18:52 ` RE:[PATCH RESEND x86-next v4] " Malaya Kumar Rout
2025-04-08 20:12 ` [PATCH " Ingo Molnar
2025-04-09 13:53 ` [PATCH " Malaya Kumar Rout
2025-04-09 19:41 ` [tip: x86/mm] selftests/x86/lam: Fix clean up fds " tip-bot2 for Malaya Kumar Rout
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=Z-J3jlYcocf_w4M_@gmail.com \
--to=mingo@kernel.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=malayarout91@gmail.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=shuah@kernel.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.