From: Alan Modra Date: Sun, 29 Dec 2019 02:25:20 +0000 (+1030) Subject: coff_close_and_cleanup X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f5d35bb7a5789950efd5f03b270d4c5f774eaba9;p=binutils-gdb.git coff_close_and_cleanup Fixes leaks in _bfd_coff_get_external_symbols and _bfd_coff_read_string_table. * coffcode.h (coff_close_and_cleanup): Redefine to.. * coffgen.c (_bfd_coff_close_and_cleanup): ..this. New function. * libcoff-in.h (_bfd_coff_close_and_cleanup): Declare. * libcoff.h: Regenerate. --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index af2ddfa5e0c..de79b5eb239 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,10 @@ +2019-12-29 Alan Modra + + * coffcode.h (coff_close_and_cleanup): Redefine to.. + * coffgen.c (_bfd_coff_close_and_cleanup): ..this. New function. + * libcoff-in.h (_bfd_coff_close_and_cleanup): Declare. + * libcoff.h: Regenerate. + 2019-12-29 Hannes Domani Alan Modra diff --git a/bfd/coffcode.h b/bfd/coffcode.h index ac5312fdb03..7bf7d68e03d 100644 --- a/bfd/coffcode.h +++ b/bfd/coffcode.h @@ -5642,7 +5642,7 @@ static bfd_coff_backend_data bigobj_swap_table = #endif /* COFF_WITH_PE_BIGOBJ */ #ifndef coff_close_and_cleanup -#define coff_close_and_cleanup _bfd_generic_close_and_cleanup +#define coff_close_and_cleanup _bfd_coff_close_and_cleanup #endif #ifndef coff_bfd_free_cached_info diff --git a/bfd/coffgen.c b/bfd/coffgen.c index 7f26e18c450..57a18b02dc1 100644 --- a/bfd/coffgen.c +++ b/bfd/coffgen.c @@ -3161,3 +3161,18 @@ bfd_coff_group_name (bfd *abfd, const asection *sec) return ci->name; return NULL; } + +bfd_boolean +_bfd_coff_close_and_cleanup (bfd *abfd) +{ + if (abfd->format == bfd_object + && bfd_family_coff (abfd) + && coff_data (abfd) != NULL) + { + obj_coff_keep_syms (abfd) = FALSE; + obj_coff_keep_strings (abfd) = FALSE; + if (!_bfd_coff_free_symbols (abfd)) + return FALSE; + } + return _bfd_generic_close_and_cleanup (abfd); +} diff --git a/bfd/libcoff-in.h b/bfd/libcoff-in.h index 031622f0187..a4623dd903f 100644 --- a/bfd/libcoff-in.h +++ b/bfd/libcoff-in.h @@ -367,6 +367,8 @@ extern bfd_vma bfd_coff_reloc16_get_value (arelent *, struct bfd_link_info *, asection *); extern void bfd_perform_slip (bfd *, unsigned int, asection *, bfd_vma); +extern bfd_boolean _bfd_coff_close_and_cleanup + (bfd *); /* Functions and types in cofflink.c. */ diff --git a/bfd/libcoff.h b/bfd/libcoff.h index 093f1b41594..e9cade86bbb 100644 --- a/bfd/libcoff.h +++ b/bfd/libcoff.h @@ -371,6 +371,8 @@ extern bfd_vma bfd_coff_reloc16_get_value (arelent *, struct bfd_link_info *, asection *); extern void bfd_perform_slip (bfd *, unsigned int, asection *, bfd_vma); +extern bfd_boolean _bfd_coff_close_and_cleanup + (bfd *); /* Functions and types in cofflink.c. */