Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1739643

Re: [PATCH] tools: firewire: nosy-dump: fix a resource leak in main()

From Stefan Richter <stefanr@s5r6.in-berlin.de>
Newsgroups linux.kernel
Subject Re: [PATCH] tools: firewire: nosy-dump: fix a resource leak in main()
Date 2017-09-26 10:00 +0200
Message-ID <utSWC-1N5-15@gated-at.bofh.it> (permalink)
References <upkAa-2u5-15@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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/

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[PATCH] tools: firewire: nosy-dump: fix a resource leak in main() Martin Kepplinger <martink@posteo.de> - 2017-09-13 20:30 +0200
  Re: [PATCH] tools: firewire: nosy-dump: fix a resource leak in  main() Stefan Richter <stefanr@s5r6.in-berlin.de> - 2017-09-26 10:00 +0200

csiph-web