]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gas: replace bfd_alloc with notes_alloc
authorAlan Modra <amodra@gmail.com>
Thu, 13 Feb 2025 00:29:51 +0000 (10:59 +1030)
committerAlan Modra <amodra@gmail.com>
Thu, 13 Feb 2025 21:56:42 +0000 (08:26 +1030)
bfd_alloc can return NULL on out-of-memory so code needs to check the
return value and print an error.  That check was missing in write.c.
notes_alloc won't return NULL, instead the underlying obstack_alloc
prints an OOM message and the process exits.  This is more convenient,
and when the bfd_alloc memory is attached to the gas output bfd it is
released only slightly before the notes obstack.

* config/obj-macho.c (obj_mach_o_set_indirect_symbols): Use
notes_calloc rather than bfd_zalloc.
* write.c (set_symtab): Use notes_alloc.

gas/config/obj-macho.c
gas/write.c

index 249791f90819e139e5d2764b1b98c2b3db76960e..89c2e0494dbf8d8d4a22f8c09b0e4573079b4964 100644 (file)
@@ -1818,13 +1818,8 @@ obj_mach_o_set_indirect_symbols (bfd *abfd, asection *sec,
              if (nactual < bfd_get_symcount (abfd))
                nactual = bfd_get_symcount (abfd);
 
-             ms->indirect_syms =
-                       bfd_zalloc (abfd,
-                                   nactual * sizeof (bfd_mach_o_asymbol *));
-
-             if (ms->indirect_syms == NULL)
-               as_fatal (_("internal error: failed to allocate %d indirect"
-                           "symbol pointers"), nactual);
+             ms->indirect_syms = notes_calloc (nactual,
+                                               sizeof (*ms->indirect_syms));
 
              for (isym = list, n = 0; isym != NULL; isym = isym->next, n++)
                {
index 439f6a6913a7521056fa38e842b7dec9bac2c4a8..325c4402061239d79ef703c55076bc2869d75dca 100644 (file)
@@ -1804,9 +1804,8 @@ set_symtab (void)
   if (nsyms)
     {
       int i;
-      bfd_size_type amt = (bfd_size_type) nsyms * sizeof (asymbol *);
 
-      asympp = (asymbol **) bfd_alloc (stdoutput, amt);
+      asympp = notes_alloc (nsyms * sizeof (asymbol *));
       symp = symbol_rootP;
       for (i = 0; i < nsyms; symp = symbol_next (symp))
        if (!symbol_removed_p (symp)