Bug 816494 part 3 - Allocate Elf instance on stack in do_file(). r=nfroyd,a=akeybl
authorMike Hommey <mh+mozilla@glandium.org>
Mon, 10 Dec 2012 10:33:08 +0100
changeset 119179 0881ada9a7499aea3cee53a8a312c63ad301aca3
parent 119178 9f952d7c6bb1d74d4e7fbb03186a4b478d2d7cab
child 119180 d7f812ae0ab1c19550cc30d227b1caf9477ded70
push id3101
push usermh@glandium.org
push dateFri, 04 Jan 2013 14:49:20 +0000
treeherdermozilla-aurora@84efed665a29 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnfroyd, akeybl
bugs816494
milestone19.0a2
Bug 816494 part 3 - Allocate Elf instance on stack in do_file(). r=nfroyd,a=akeybl
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], '/');