PR24955, libbfd terminating program on out of memory
authorAlan Modra <amodra@gmail.com>
Mon, 2 Sep 2019 06:43:05 +0000 (16:13 +0930)
committerAlan Modra <amodra@gmail.com>
Thu, 5 Sep 2019 02:03:34 +0000 (11:33 +0930)
commit89bdc77eabf5ede68322f6e47e003c1dc45b9ccb
tree87e650254fe116fdf69906ca003a0d8c34c491ac
parent809f9153986595498fbb59e547ea4e75a94a50f6
PR24955, libbfd terminating program on out of memory

This patch fixes the worst of the cases where libbfd might terminate
a program due to calling xstrdup or xmalloc.  I've also fixed some
error paths that didn't clean up properly.

PR 24955
* libbfd-in.h (bfd_strdup): New inline function.
* archive.c (_bfd_get_elt_at_filepos): Use bfd_strdup.  Close
bfd on error.
* elfcode.h (_bfd_elf_bfd_from_remote_memory): Use bfd_strdup.
* opncls.c (bfd_fopen): Use bfd_strdup.  Close fd and stream
on error.
(bfd_openstreamr): Use bfd_strdup.
(bfd_openr_iovec, bfd_openw, bfd_create): Likewise.
* plugin.c (try_load_plugin): Use bfd_malloc.
* libbfd.h: Regenerate.
bfd/ChangeLog
bfd/archive.c
bfd/elfcode.h
bfd/libbfd-in.h
bfd/libbfd.h
bfd/opncls.c
bfd/plugin.c