Bug 1414947 - elfhack/elf.cpp:167 possible memory leak
MozReview-Commit-ID: 5NvqNR8wRKn
--- a/build/unix/elfhack/elf.cpp
+++ b/build/unix/elfhack/elf.cpp
@@ -158,22 +158,29 @@ Elf::Elf(std::ifstream &file)
for (int i = 0; i < ehdr->e_shnum; i++)
shdr[i] = new Elf_Shdr(file, e_ident[EI_CLASS], e_ident[EI_DATA]);
// Sanity check in section header for index 0
if ((shdr[0]->sh_name != 0) || (shdr[0]->sh_type != SHT_NULL) ||
(shdr[0]->sh_flags != 0) || (shdr[0]->sh_addr != 0) ||
(shdr[0]->sh_offset != 0) || (shdr[0]->sh_size != 0) ||
(shdr[0]->sh_link != SHN_UNDEF) || (shdr[0]->sh_info != 0) ||
- (shdr[0]->sh_addralign != 0) || (shdr[0]->sh_entsize != 0))
+ (shdr[0]->sh_addralign != 0) || (shdr[0]->sh_entsize != 0)) {
+ for (int i = 0; i < ehdr->e_shnum; i++)
+ delete shdr[i];
+ delete[] shdr;
throw std::runtime_error("Section header for index 0 contains unsupported values");
+ }
- if ((shdr[ehdr->e_shstrndx]->sh_link != 0) || (shdr[ehdr->e_shstrndx]->sh_info != 0))
+ if ((shdr[ehdr->e_shstrndx]->sh_link != 0) || (shdr[ehdr->e_shstrndx]->sh_info != 0)) {
+ for (int i = 0; i < ehdr->e_shnum; i++)
+ delete shdr[i];
+ delete[] shdr;
throw std::runtime_error("unsupported ELF content: string table with sh_link != 0 || sh_info != 0");
-
+ }
// Store these temporarily
tmp_shdr = shdr;
tmp_file = &file;
// Fill sections list
sections = new ElfSection *[ehdr->e_shnum];
for (int i = 0; i < ehdr->e_shnum; i++)
sections[i] = nullptr;