Skip to contentSkip to conversation

x86: boot/compressed/mkpiggy.c: fix resource leakage

PATCH In review Cong Ding 2 participants 2 messages Jan 14, 2013 – Jan 15, 2013 x86

lore
Share & tools
lore

Cong Ding

author
#0 lore raw

PATCH 1/1 x86: boot/compressed/mkpiggy.c: fix resource leakage

the file should be closed if it goes to error.

---
 arch/x86/boot/compressed/mkpiggy.c |    1 +
 1 file changed, 1 insertion(+)
arch/x86/boot/compressed/mkpiggy.c +1 -0
index 958a641..e29154f 100644
@@ -58,6 +58,7 @@ int main(int argc, char *argv[])
 
 	if (fread(&olen, sizeof(olen), 1, f) != 1) {
 		perror(argv[1]);
+		fclose(f);
 		return 1;
 	}
 
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 2 lines · Cong Ding

the file should be closed if it goes to error.

What tool are you using to generate all these patches?

Quoted 10 lines
---
  arch/x86/boot/compressed/mkpiggy.c |    1 +
  1 file changed, 1 insertion(+)
arch/x86/boot/compressed/mkpiggy.c +0 -0
index 958a641..e29154f 100644

arch/x86/boot/compressed/mkpiggy.c int main(int argc, char *argv[]) · line 61

Quoted 4 lines
arch/x86/boot/compressed/mkpiggy.c +1 -0
@@ -58,6 +58,7 @@ int main(int argc, char *argv[])
 
  	if (fread(&olen, sizeof(olen), 1, f) != 1) {
  		perror(argv[1]);
+		fclose(f);

The next line is a return from main(). All FILEs will be automatically closed by the C library, so your change is redundant.

The x86 maintainers can do what ever they want with it. But to me, it seems like unnecessary code churn.

David Daney

Quoted 4 lines
arch/x86/boot/compressed/mkpiggy.c +0 -0
  		return 1;
  	}