Bug 816494 part 3 - Allocate Elf instance on stack in do_file(). r=nfroyd
authorMike Hommey <mh+mozilla@glandium.org>
Mon, 10 Dec 2012 10:33:08 +0100
changeset 115477 d2ebcd9235d106fd42b5a16a5c866873fe75823e
parent 115476 84ad94351bf3586470298c8543cb8bb025ec246d
child 115478 0e9bc6febd7f0592e61556235d66caa53ae92ebe
push id24008
push userryanvm@gmail.com
push dateMon, 10 Dec 2012 18:56:37 +0000
treeherdermozilla-central@00e26dece6ea [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnfroyd
bugs816494
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 816494 part 3 - Allocate Elf instance on stack in do_file(). r=nfroyd
build/unix/elfhack/elfhack.cpp
--- a/build/unix/elfhack/elfhack.cpp
+++ b/build/unix/elfhack/elfhack.cpp
@@ -597,59 +597,56 @@ static inline int backup_file(const char
     std::string fname(name);
     fname += ".bak";
     return rename(name, fname.c_str());
 }
 
 void do_file(const char *name, bool backup = false, bool force = false)
 {
     std::ifstream file(name, std::ios::in|std::ios::binary);
-    Elf *elf = new Elf(file);
-    unsigned int size = elf->getSize();
+    Elf elf(file);
+    unsigned int size = elf.getSize();
     fprintf(stderr, "%s: ", name);
-    if (elf->getType() != ET_DYN) {
+    if (elf.getType() != ET_DYN) {
         fprintf(stderr, "Not a shared object. Skipping\n");
-        delete elf;
         return;
     }
 
-    for (ElfSection *section = elf->getSection(1); section != NULL;
+    for (ElfSection *section = elf.getSection(1); section != NULL;
          section = section->getNext()) {
         if (section->getName() &&
             (strncmp(section->getName(), ".elfhack.", 9) == 0)) {
             fprintf(stderr, "Already elfhacked. Skipping\n");
-            delete elf;
             return;
         }
     }
 
     int exit = -1;
-    switch (elf->getMachine()) {
+    switch (elf.getMachine()) {
     case EM_386:
-        exit = do_relocation_section<Elf_Rel>(elf, R_386_RELATIVE, R_386_32, force);
+        exit = do_relocation_section<Elf_Rel>(&elf, R_386_RELATIVE, R_386_32, force);
         break;
     case EM_X86_64:
-        exit = do_relocation_section<Elf_Rela>(elf, R_X86_64_RELATIVE, R_X86_64_64, force);
+        exit = do_relocation_section<Elf_Rela>(&elf, R_X86_64_RELATIVE, R_X86_64_64, force);
         break;
     case EM_ARM:
-        exit = do_relocation_section<Elf_Rel>(elf, R_ARM_RELATIVE, R_ARM_ABS32, force);
+        exit = do_relocation_section<Elf_Rel>(&elf, R_ARM_RELATIVE, R_ARM_ABS32, force);
         break;
     }
     if (exit == 0) {
-        if (!force && (elf->getSize() >= size)) {
+        if (!force && (elf.getSize() >= size)) {
             fprintf(stderr, "No gain. Skipping\n");
         } else if (backup && backup_file(name) != 0) {
             fprintf(stderr, "Couln't create backup file\n");
         } else {
             std::ofstream ofile(name, std::ios::out|std::ios::binary|std::ios::trunc);
-            elf->write(ofile);
-            fprintf(stderr, "Reduced by %d bytes\n", size - elf->getSize());
+            elf.write(ofile);
+            fprintf(stderr, "Reduced by %d bytes\n", size - elf.getSize());
         }
     }
-    delete elf;
 }
 
 int main(int argc, char *argv[])
 {
     int arg;
     bool backup = false;
     bool force = false;
     char *lastSlash = rindex(argv[0], '/');