All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Geyslan G. Bem" <geyslan@gmail.com>
To: hpa@zytor.com, tglx@linutronix.de, mingo@redhat.com, x86@kernel.org
Cc: linux-kernel@vger.kernel.org, kernel-br@googlegroups.com,
	"Geyslan G. Bem" <geyslan@gmail.com>
Subject: [PATCH] x86: mkpiggy.c: fix resource leakage
Date: Mon,  7 Oct 2013 19:16:59 -0300	[thread overview]
Message-ID: <1381184219-10985-1-git-send-email-geyslan@gmail.com> (raw)

Even though the resource is released when the application is closed or
when returned from main function, modified to make it in accordance.
Now FILE pointer is always verified.

Signed-off-by: Geyslan G. Bem <geyslan@gmail.com>
---
 arch/x86/boot/compressed/mkpiggy.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/arch/x86/boot/compressed/mkpiggy.c b/arch/x86/boot/compressed/mkpiggy.c
index 958a641..b669ab6 100644
--- a/arch/x86/boot/compressed/mkpiggy.c
+++ b/arch/x86/boot/compressed/mkpiggy.c
@@ -36,11 +36,12 @@ int main(int argc, char *argv[])
 	uint32_t olen;
 	long ilen;
 	unsigned long offs;
-	FILE *f;
+	FILE *f = NULL;
+	int retval = 1;
 
 	if (argc < 2) {
 		fprintf(stderr, "Usage: %s compressed_file\n", argv[0]);
-		return 1;
+		goto bail;
 	}
 
 	/* Get the information for the compressed kernel image first */
@@ -48,7 +49,7 @@ int main(int argc, char *argv[])
 	f = fopen(argv[1], "r");
 	if (!f) {
 		perror(argv[1]);
-		return 1;
+		goto bail;
 	}
 
 
@@ -58,12 +59,11 @@ int main(int argc, char *argv[])
 
 	if (fread(&olen, sizeof(olen), 1, f) != 1) {
 		perror(argv[1]);
-		return 1;
+		goto bail;
 	}
 
 	ilen = ftell(f);
 	olen = get_unaligned_le32(&olen);
-	fclose(f);
 
 	/*
 	 * Now we have the input (compressed) and output (uncompressed)
@@ -91,5 +91,9 @@ int main(int argc, char *argv[])
 	printf(".incbin \"%s\"\n", argv[1]);
 	printf("input_data_end:\n");
 
-	return 0;
+	retval = 0;
+bail:
+	if (f)
+		fclose(f);
+	return retval;
 }
-- 
1.8.4


             reply	other threads:[~2013-10-07 22:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-07 22:16 Geyslan G. Bem [this message]
2013-10-07 22:36 ` [PATCH] x86: mkpiggy.c: fix resource leakage H. Peter Anvin
2013-10-07 22:44 ` H. Peter Anvin
2013-10-07 23:41   ` Geyslan Gregório Bem
2013-10-08 18:39 ` [tip:x86/cleanups] x86: mkpiggy.c: Explicitly close the output file tip-bot for Geyslan G. Bem

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=1381184219-10985-1-git-send-email-geyslan@gmail.com \
    --to=geyslan@gmail.com \
    --cc=hpa@zytor.com \
    --cc=kernel-br@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.