* [PATCH] MIPS: tools: Fix resource leak in elf-entry.c
@ 2020-05-14 12:59 Kaige Li
2020-05-24 7:41 ` Thomas Bogendoerfer
0 siblings, 1 reply; 2+ messages in thread
From: Kaige Li @ 2020-05-14 12:59 UTC (permalink / raw)
To: Thomas Bogendoerfer; +Cc: linux-mips, Tiezhu Yang, Xuefeng Li
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>
---
arch/mips/tools/elf-entry.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/arch/mips/tools/elf-entry.c b/arch/mips/tools/elf-entry.c
index adde79c..dbd14ff 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;
}
--
2.1.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] MIPS: tools: Fix resource leak in elf-entry.c
2020-05-14 12:59 [PATCH] MIPS: tools: Fix resource leak in elf-entry.c Kaige Li
@ 2020-05-24 7:41 ` Thomas Bogendoerfer
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Bogendoerfer @ 2020-05-24 7:41 UTC (permalink / raw)
To: Kaige Li; +Cc: linux-mips, Tiezhu Yang, Xuefeng Li
On Thu, May 14, 2020 at 08:59:41PM +0800, Kaige Li wrote:
> 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>
> ---
> arch/mips/tools/elf-entry.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
applied to mips-next.
Thomas.
--
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea. [ RFC1925, 2.3 ]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-05-24 8:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-05-14 12:59 [PATCH] MIPS: tools: Fix resource leak in elf-entry.c Kaige Li
2020-05-24 7:41 ` Thomas Bogendoerfer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).