* [PATCH scripts] scripts/sorttable: Fix resource leak in parse_symbols()
@ 2025-02-25 5:37 Dheeraj Reddy Jonnalagadda
2025-02-25 15:52 ` Steven Rostedt
0 siblings, 1 reply; 2+ messages in thread
From: Dheeraj Reddy Jonnalagadda @ 2025-02-25 5:37 UTC (permalink / raw)
To: rostedt; +Cc: catalin.marinas, linux-kernel, Dheeraj Reddy Jonnalagadda
Fix a resource leak in parse_symbols() where the file pointer fp
was not closed if add_field() returned an error. This caused an
open file descriptor to remain unclosed. Ensure that fp is properly
closed before returning an error.
Fixes: ef378c3b8233 ("scripts/sorttable: Zero out weak functions in mcount_loc table")
Signed-off-by: Dheeraj Reddy Jonnalagadda <dheeraj.linuxdev@gmail.com>
---
scripts/sorttable.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/scripts/sorttable.c b/scripts/sorttable.c
index 23c7e0e6c024..b9b066c1afee 100644
--- a/scripts/sorttable.c
+++ b/scripts/sorttable.c
@@ -662,8 +662,10 @@ static int parse_symbols(const char *fname)
addr = strtoull(addr_str, NULL, 16);
size = strtoull(size_str, NULL, 16);
- if (add_field(addr, size) < 0)
+ if (add_field(addr, size) < 0) {
+ fclose(fp);
return -1;
+ }
}
fclose(fp);
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH scripts] scripts/sorttable: Fix resource leak in parse_symbols()
2025-02-25 5:37 [PATCH scripts] scripts/sorttable: Fix resource leak in parse_symbols() Dheeraj Reddy Jonnalagadda
@ 2025-02-25 15:52 ` Steven Rostedt
0 siblings, 0 replies; 2+ messages in thread
From: Steven Rostedt @ 2025-02-25 15:52 UTC (permalink / raw)
To: Dheeraj Reddy Jonnalagadda; +Cc: catalin.marinas, linux-kernel
On Tue, 25 Feb 2025 11:07:24 +0530
Dheeraj Reddy Jonnalagadda <dheeraj.linuxdev@gmail.com> wrote:
> Fix a resource leak in parse_symbols() where the file pointer fp
> was not closed if add_field() returned an error. This caused an
> open file descriptor to remain unclosed. Ensure that fp is properly
> closed before returning an error.
>
> Fixes: ef378c3b8233 ("scripts/sorttable: Zero out weak functions in mcount_loc table")
Thanks, but this isn't needed. If it returns -1 it will exit the program.
When a program exits, it will close all opened file descriptors.
I may add it just because it's proper to close descriptors in case this
function is used for something else (highly unlikely). But it's not fixing
anything, and there is no "leak".
-- Steve
> Signed-off-by: Dheeraj Reddy Jonnalagadda <dheeraj.linuxdev@gmail.com>
> ---
> scripts/sorttable.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/scripts/sorttable.c b/scripts/sorttable.c
> index 23c7e0e6c024..b9b066c1afee 100644
> --- a/scripts/sorttable.c
> +++ b/scripts/sorttable.c
> @@ -662,8 +662,10 @@ static int parse_symbols(const char *fname)
>
> addr = strtoull(addr_str, NULL, 16);
> size = strtoull(size_str, NULL, 16);
> - if (add_field(addr, size) < 0)
> + if (add_field(addr, size) < 0) {
> + fclose(fp);
> return -1;
> + }
> }
> fclose(fp);
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-02-25 15:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-25 5:37 [PATCH scripts] scripts/sorttable: Fix resource leak in parse_symbols() Dheeraj Reddy Jonnalagadda
2025-02-25 15:52 ` Steven Rostedt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox