[PATCH] bfd: Add bfd_xalloc, bfd_xzalloc and bfd_xalloc_strdup

Alan Modra amodra@gmail.com
Wed Apr 10 23:44:50 GMT 2024


On Tue, Apr 09, 2024 at 04:01:44PM -0700, H.J. Lu wrote:
> Remove bfd_xalloc in binutils.  Add bfd_xalloc, bfd_xzalloc and
> bfd_xalloc_strdup to bfd to fix memory leaks in read.c, write.c and
> obj-elf.c.

NAK.  The "x" names imply a function that does not return on failure,
yet bfd_xallox does.  You even assume that yourself, eg. in the
following:

> +void *
> +bfd_xzalloc (bfd *abfd, bfd_size_type wanted)
> +{
> +  void *res = bfd_xalloc (abfd, wanted);
> +  memset (res, 0, (size_t) wanted);
> +  return res;
> +}

I don't see any point in adding these functions to libbfd.

-- 
Alan Modra
Australia Development Lab, IBM


More information about the Binutils mailing list