summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaige Li <likaige@loongson.cn>2020-05-14 14:59:41 +0200
committerThomas Bogendoerfer <tsbogend@alpha.franken.de>2020-05-24 09:29:48 +0200
commitf33a0b941017b9cb5a4e975af198b855b2f2b455 (patch)
tree64a889f01a10373363e0f17e2aa754f6993d3d63
parentMIPS: SGI-IP30: Reorder the macros in war.h (diff)
downloadlinux-f33a0b941017b9cb5a4e975af198b855b2f2b455.tar.xz
linux-f33a0b941017b9cb5a4e975af198b855b2f2b455.zip
MIPS: tools: Fix resource leak in elf-entry.c
There is a file descriptor resource leak in elf-entry.c, fix this by adding fclose() before return and die. Signed-off-by: Kaige Li <likaige@loongson.cn> Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
-rw-r--r--arch/mips/tools/elf-entry.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/arch/mips/tools/elf-entry.c b/arch/mips/tools/elf-entry.c
index adde79ce7fc0..dbd14ff05b4c 100644
--- a/arch/mips/tools/elf-entry.c
+++ b/arch/mips/tools/elf-entry.c
@@ -51,11 +51,14 @@ int main(int argc, const char *argv[])
nread = fread(&hdr, 1, sizeof(hdr), file);
if (nread != sizeof(hdr)) {
perror("Unable to read input file");
+ fclose(file);
return EXIT_FAILURE;
}
- if (memcmp(hdr.ehdr32.e_ident, ELFMAG, SELFMAG))
+ if (memcmp(hdr.ehdr32.e_ident, ELFMAG, SELFMAG)) {
+ fclose(file);
die("Input is not an ELF\n");
+ }
switch (hdr.ehdr32.e_ident[EI_CLASS]) {
case ELFCLASS32:
@@ -67,6 +70,7 @@ int main(int argc, const char *argv[])
entry = be32toh(hdr.ehdr32.e_entry);
break;
default:
+ fclose(file);
die("Invalid ELF encoding\n");
}
@@ -83,14 +87,17 @@ int main(int argc, const char *argv[])
entry = be64toh(hdr.ehdr64.e_entry);
break;
default:
+ fclose(file);
die("Invalid ELF encoding\n");
}
break;
default:
+ fclose(file);
die("Invalid ELF class\n");
}
printf("0x%016" PRIx64 "\n", entry);
+ fclose(file);
return EXIT_SUCCESS;
}