1
0
Fork 0

MIPS: tools: Fix resource leak in elf-entry.c

[ Upstream commit f33a0b9410 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
5.4-rM2-2.2.x-imx-squashed
Kaige Li 2020-05-14 20:59:41 +08:00 committed by Greg Kroah-Hartman
parent 87ef5086a3
commit ce066ce05e
1 changed files with 8 additions and 1 deletions

View File

@ -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;
}