Skip to contentSkip to conversation

tools: firewire: nosy-dump: fix a resource leak in main()

PATCH In review Martin Kepplinger 2 participants 2 messages Sep 13, 2017 – Sep 26, 2017 Firewire

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools: firewire: nosy-dump: fix a resource leak in main()

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.

---
 tools/firewire/nosy-dump.c | 2 ++
 1 file changed, 2 insertions(+)
tools/firewire/nosy-dump.c +2 -0
index 3179c711bd65..228be406f206 100644
@@ -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;
 		}
 	}
Signature · 1 line
2.11.0
#1 lore raw
Quoted 14 lines · 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.

---
 tools/firewire/nosy-dump.c | 2 ++
 1 file changed, 2 insertions(+)
tools/firewire/nosy-dump.c +0 -0
index 3179c711bd65..228be406f206 100644

tools/firewire/nosy-dump.c int main(int argc, const char *argv[]) · line 967

Quoted 8 lines
tools/firewire/nosy-dump.c +2 -0
@@ -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.

Signature · 3 lines
Stefan Richter
-======----= =--= ==-=-
http://arcgraph.de/sr/