[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Z-J3jlYcocf_w4M_@gmail.com>
Date: Tue, 25 Mar 2025 10:29:50 +0100
From: Ingo Molnar <mingo@...nel.org>
To: Peter Zijlstra <peterz@...radead.org>
Cc: Malaya Kumar Rout <malayarout91@...il.com>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
"H. Peter Anvin" <hpa@...or.com>, Shuah Khan <shuah@...nel.org>,
linux-kernel@...r.kernel.org, linux-kselftest@...r.kernel.org
Subject: Re: [PATCH] selftests/x86/lam: fix memory leak and resource leak in
lam.c
* Peter Zijlstra <peterz@...radead.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
Powered by blists - more mailing lists