Skip to contentSkip to conversation

scripts/sorttable: Fix resource leak on file pointer fp

PATCH In review Colin Ian King 3 participants 4 messages Feb 26, 2025 – Feb 27, 2025 Kernel janitors

lore
Share & tools
lore
#0 lore raw

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.

Fixes ef378c3b8233 ("scripts/sorttable: Zero out weak functions in mcount_loc table")
---
 scripts/sorttable.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
scripts/sorttable.c +3 -1
index 7b4b3714b1af..e35abf28d037 100644
@@ -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
#1 lore raw
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_symbols that 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")
---
 scripts/sorttable.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
scripts/sorttable.c +3 -1
index 7b4b3714b1af..e35abf28d037 100644
@@ -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);
 
#2 lore raw
In reply to Colin Ian King
Quoted 6 lines · Colin Ian King

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.

Fixes ef378c3b8233 ("scripts/sorttable: Zero out weak functions in mcount_loc table")

This is in scripts/ so it doesn't really matter. We're going to exit and release everything immediately either way.

regards,
dan carpenter

#3 lore raw
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_symbols that causes a resource leak. Fix this by adding in the missing fclose.

Fixes ef378c3b8233 ("scripts/sorttable: Zero out weak functions in mcount_loc table")

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