All of lore.kernel.org
 help / color / mirror / Atom feed
From: Martin Kepplinger <martink@posteo.de>
To: stefanr@s5r6.in-berlin.de
Cc: linux1394-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org,
	Martin Kepplinger <martink@posteo.de>
Subject: [PATCH] tools: firewire: nosy-dump: fix a resource leak in main()
Date: Wed, 13 Sep 2017 20:21:16 +0200	[thread overview]
Message-ID: <20170913182116.24694-1-martink@posteo.de> (raw)

If option_input and option_output is true two files are opened
consecutively. In case the second fopen() fails, let's fclose()
the first one before returning early.

Signed-off-by: Martin Kepplinger <martink@posteo.de>
---
 tools/firewire/nosy-dump.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/firewire/nosy-dump.c b/tools/firewire/nosy-dump.c
index 3179c711bd65..228be406f206 100644
--- a/tools/firewire/nosy-dump.c
+++ b/tools/firewire/nosy-dump.c
@@ -960,6 +960,8 @@ int main(int argc, const char *argv[])
 		output = fopen(option_output, "w");
 		if (output == NULL) {
 			fprintf(stderr, "Could not open %s, %m\n", option_output);
+			if (input)
+				fclose(input);
 			return -1;
 		}
 	}
-- 
2.11.0

             reply	other threads:[~2017-09-13 18:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-13 18:21 Martin Kepplinger [this message]
2017-09-26  7:35 ` [PATCH] tools: firewire: nosy-dump: fix a resource leak in main() Stefan Richter

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=20170913182116.24694-1-martink@posteo.de \
    --to=martink@posteo.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux1394-devel@lists.sourceforge.net \
    --cc=stefanr@s5r6.in-berlin.de \
    /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.