mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Weigang He <geoffreyhe2@gmail.com>
To: masahiroy@kernel.org
Cc: petr.pavlu@suse.com, sam@ravnborg.org,
	linux-kernel@vger.kernel.org, Weigang He <geoffreyhe2@gmail.com>
Subject: [PATCH] genksyms: fix file pointer leaks on error paths
Date: Sat, 17 Jan 2026 10:26:02 +0000	[thread overview]
Message-ID: <20260117102602.534734-1-geoffreyhe2@gmail.com> (raw)

The option parsing loop processes multiple command-line options
sequentially. When -r or -T options successfully open their files,
but a later option causes an early return (e.g., -h for help, an
unknown option, or a failed fopen), the previously opened file
pointers are leaked.

Fix this by closing ref_file and dumpfile before each early return
in the option parsing switch statement.

Fixes: 64e6c1e12372 ("genksyms: track symbol checksum changes")
Signed-off-by: Weigang He <geoffreyhe2@gmail.com>
---
 scripts/genksyms/genksyms.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/scripts/genksyms/genksyms.c b/scripts/genksyms/genksyms.c
index 83e48670c2fcf..dee9216797935 100644
--- a/scripts/genksyms/genksyms.c
+++ b/scripts/genksyms/genksyms.c
@@ -776,6 +776,8 @@ int main(int argc, char **argv)
 			ref_file = fopen(optarg, "r");
 			if (!ref_file) {
 				perror(optarg);
+				if (dumpfile)
+					fclose(dumpfile);
 				return 1;
 			}
 			break;
@@ -784,6 +786,8 @@ int main(int argc, char **argv)
 			dumpfile = fopen(optarg, "w");
 			if (!dumpfile) {
 				perror(optarg);
+				if (ref_file)
+					fclose(ref_file);
 				return 1;
 			}
 			break;
@@ -792,9 +796,17 @@ int main(int argc, char **argv)
 			break;
 		case 'h':
 			genksyms_usage();
+			if (ref_file)
+				fclose(ref_file);
+			if (dumpfile)
+				fclose(dumpfile);
 			return 0;
 		default:
 			genksyms_usage();
+			if (ref_file)
+				fclose(ref_file);
+			if (dumpfile)
+				fclose(dumpfile);
 			return 1;
 		}
 	{
-- 
2.34.1


             reply	other threads:[~2026-01-17 10:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-17 10:26 Weigang He [this message]
2026-01-20 11:48 ` Petr Pavlu

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=20260117102602.534734-1-geoffreyhe2@gmail.com \
    --to=geoffreyhe2@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=petr.pavlu@suse.com \
    --cc=sam@ravnborg.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®