All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Richter <stefanr@s5r6.in-berlin.de>
To: Martin Kepplinger <martink@posteo.de>
Cc: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] tools: firewire: nosy-dump: fix a resource leak in main()
Date: Tue, 26 Sep 2017 09:35:23 +0200	[thread overview]
Message-ID: <20170926093523.343c9a6c@kant> (raw)
In-Reply-To: <20170913182116.24694-1-martink@posteo.de>

On Sep 13 Martin Kepplinger wrote:
> 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;
>  		}
>  	}

When we return from main(), all files are closed implicitly.
-- 
Stefan Richter
-======----= =--= ==-=-
http://arcgraph.de/sr/

      reply	other threads:[~2017-09-26  7:49 UTC|newest]

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

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