Bug 1414947 - elfhack/elf.cpp:167 possible memory leak draft
authorJean-Luc Bonnafoux <jeanluc.bonnafoux@wanadoo.fr>
Tue, 07 Nov 2017 11:19:56 +0100
changeset 699164 ef69f21b41e22b3bd1c7ccf36404aa93ee0139a3
parent 699163 a3cb6034f516420d85c5f9f8d2edf366a0c5d861
child 714811 a5ee96c1dff69c4c651dbeff393d57f7a69300ea
child 714813 df0c9d61361f1c0425944a58081bf3cfe921cc94
push id89484
push userbmo:jeanluc.bonnafoux@wanadoo.fr
push dateThu, 16 Nov 2017 18:54:15 +0000
bugs1414947
milestone58.0a1
Bug 1414947 - elfhack/elf.cpp:167 possible memory leak MozReview-Commit-ID: 5NvqNR8wRKn
build/unix/elfhack/elf.cpp
--- 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;