Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Kaige Li and committed by
Thomas Bogendoerfer
f33a0b94 b34a1a71

+8 -1
+8 -1
arch/mips/tools/elf-entry.c
··· 51 51 nread = fread(&hdr, 1, sizeof(hdr), file); 52 52 if (nread != sizeof(hdr)) { 53 53 perror("Unable to read input file"); 54 + fclose(file); 54 55 return EXIT_FAILURE; 55 56 } 56 57 57 - if (memcmp(hdr.ehdr32.e_ident, ELFMAG, SELFMAG)) 58 + if (memcmp(hdr.ehdr32.e_ident, ELFMAG, SELFMAG)) { 59 + fclose(file); 58 60 die("Input is not an ELF\n"); 61 + } 59 62 60 63 switch (hdr.ehdr32.e_ident[EI_CLASS]) { 61 64 case ELFCLASS32: ··· 70 67 entry = be32toh(hdr.ehdr32.e_entry); 71 68 break; 72 69 default: 70 + fclose(file); 73 71 die("Invalid ELF encoding\n"); 74 72 } 75 73 ··· 87 83 entry = be64toh(hdr.ehdr64.e_entry); 88 84 break; 89 85 default: 86 + fclose(file); 90 87 die("Invalid ELF encoding\n"); 91 88 } 92 89 break; 93 90 94 91 default: 92 + fclose(file); 95 93 die("Invalid ELF class\n"); 96 94 } 97 95 98 96 printf("0x%016" PRIx64 "\n", entry); 97 + fclose(file); 99 98 return EXIT_SUCCESS; 100 99 }