]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
elf_x86_64_scan_relocs error paths
authorAlan Modra <amodra@gmail.com>
Sun, 12 Jan 2025 04:05:02 +0000 (14:35 +1030)
committerAlan Modra <amodra@gmail.com>
Wed, 15 Jan 2025 22:53:23 +0000 (09:23 +1030)
Fix some memory leaks.

* elf64-x86-64.c (elf_x86_64_scan_relocs): Ensure error return
paths that should free relocs go via error_return.

bfd/elf64-x86-64.c

index 3f0ad680ef13f9ec5c3e8ca838003aaae34bcd85..2afc594286e57fdf3fff08f04abd284c55de08cf 100644 (file)
@@ -2272,7 +2272,7 @@ elf_x86_64_scan_relocs (bfd *abfd, struct bfd_link_info *info,
 
       if (!_bfd_elf_x86_valid_reloc_p (sec, info, htab, rel, h, isym,
                                       symtab_hdr, &no_dynreloc))
-       return false;
+       goto error_return;
 
       if (! elf_x86_64_tls_transition (info, abfd, sec, contents,
                                       symtab_hdr, sym_hashes,
@@ -2292,8 +2292,11 @@ elf_x86_64_scan_relocs (bfd *abfd, struct bfd_link_info *info,
 
        case R_X86_64_TPOFF32:
          if (!bfd_link_executable (info) && ABI_64_P (abfd))
-           return elf_x86_64_need_pic (info, abfd, sec, h, symtab_hdr, isym,
-                                       &x86_64_elf_howto_table[r_type]);
+           {
+             elf_x86_64_need_pic (info, abfd, sec, h, symtab_hdr, isym,
+                                  &x86_64_elf_howto_table[r_type]);
+             goto error_return;
+           }
          if (eh != NULL)
            eh->zero_undefweak &= 0x2;
          break;
@@ -2359,7 +2362,7 @@ elf_x86_64_scan_relocs (bfd *abfd, struct bfd_link_info *info,
 
                if (!elf_x86_allocate_local_got_info (abfd,
                                                      symtab_hdr->sh_info))
-                     goto error_return;
+                 goto error_return;
 
                /* This is a global offset table entry for a local symbol.  */
                local_got_refcounts = elf_local_got_refcounts (abfd);
@@ -2466,8 +2469,11 @@ elf_x86_64_scan_relocs (bfd *abfd, struct bfd_link_info *info,
                      && !h->def_regular
                      && h->def_dynamic
                      && (sec->flags & SEC_READONLY) == 0)))
-           return elf_x86_64_need_pic (info, abfd, sec, h, symtab_hdr, isym,
-                                       &x86_64_elf_howto_table[r_type]);
+           {
+             elf_x86_64_need_pic (info, abfd, sec, h, symtab_hdr, isym,
+                                  &x86_64_elf_howto_table[r_type]);
+             goto error_return;
+           }
          /* Fall through.  */
 
        case R_X86_64_PC8: