scripts/sorttable: Fix resource leak on file pointer fp
PATCH 1/1 scripts/sorttable: Fix resource leak on file pointer fp
There is a resource leak on fp on an error return path in function parse_symbols that causes a resource leak. Fix this by adding in the missing fclose.
--- scripts/sorttable.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
scripts/sorttable.c +3 -1
@@ -665,8 +665,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);
Signature · 1 line
2.47.2
Quoted 3 lines · On Wed, 26 Feb 2025 22:49:34 +0000 Colin Ian King <[email protected]>…
There is a resource leak on fp on an error return path in function
parse_symbolsthat causes a resource leak. Fix this by adding in the missing fclose.
This patch has already been sent, and it's not really a leak, as when this returns -1, it causes the program to exit and that will close all file descriptors.
I said I'll take the other patch as a clean up though.
https://lore.kernel.org/all/[email protected]/
-- Steve
Quoted 23 lines
Fixes ef378c3b8233 ("scripts/sorttable: Zero out weak functions in mcount_loc table")Signed-off-by Colin Ian King <[email protected]>--- scripts/sorttable.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)scripts/sorttable.c +3
-1@@ -665,8 +665,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);
Quoted 6 lines · Colin Ian King
There is a resource leak on fp on an error return path in function
parse_symbolsthat causes a resource leak. Fix this by adding in the missing fclose.Fixes ef378c3b8233 ("scripts/sorttable: Zero out weak functions in mcount_loc table")Signed-off-by Colin Ian King <[email protected]>
This is in scripts/ so it doesn't really matter. We're going to exit and release everything immediately either way.
regards,
dan carpenter
Quoted 10 lines · Dan Carpenter
Quoted 6 lines · Colin Ian King
There is a resource leak on fp on an error return path in function
parse_symbolsthat causes a resource leak. Fix this by adding in the missing fclose.Fixes ef378c3b8233 ("scripts/sorttable: Zero out weak functions in mcount_loc table")Signed-off-by Colin Ian King <[email protected]>This is in
scripts/so it doesn't really matter. We're going to exit and release everything immediately either way.
Ack. Won't fix these issues in scripts in future.
Quoted 4 lines
regards,
dan carpenter