Commit f33a0b94 authored by Kaige Li's avatar Kaige Li Committed by Thomas Bogendoerfer

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: default avatarKaige Li <likaige@loongson.cn>
Signed-off-by: default avatarThomas Bogendoerfer <tsbogend@alpha.franken.de>
parent b34a1a71
...@@ -51,11 +51,14 @@ int main(int argc, const char *argv[]) ...@@ -51,11 +51,14 @@ int main(int argc, const char *argv[])
nread = fread(&hdr, 1, sizeof(hdr), file); nread = fread(&hdr, 1, sizeof(hdr), file);
if (nread != sizeof(hdr)) { if (nread != sizeof(hdr)) {
perror("Unable to read input file"); perror("Unable to read input file");
fclose(file);
return EXIT_FAILURE; 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"); die("Input is not an ELF\n");
}
switch (hdr.ehdr32.e_ident[EI_CLASS]) { switch (hdr.ehdr32.e_ident[EI_CLASS]) {
case ELFCLASS32: case ELFCLASS32:
...@@ -67,6 +70,7 @@ int main(int argc, const char *argv[]) ...@@ -67,6 +70,7 @@ int main(int argc, const char *argv[])
entry = be32toh(hdr.ehdr32.e_entry); entry = be32toh(hdr.ehdr32.e_entry);
break; break;
default: default:
fclose(file);
die("Invalid ELF encoding\n"); die("Invalid ELF encoding\n");
} }
...@@ -83,14 +87,17 @@ int main(int argc, const char *argv[]) ...@@ -83,14 +87,17 @@ int main(int argc, const char *argv[])
entry = be64toh(hdr.ehdr64.e_entry); entry = be64toh(hdr.ehdr64.e_entry);
break; break;
default: default:
fclose(file);
die("Invalid ELF encoding\n"); die("Invalid ELF encoding\n");
} }
break; break;
default: default:
fclose(file);
die("Invalid ELF class\n"); die("Invalid ELF class\n");
} }
printf("0x%016" PRIx64 "\n", entry); printf("0x%016" PRIx64 "\n", entry);
fclose(file);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment