aboutsummaryrefslogtreecommitdiff
path: root/bfd/coffgen.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2023-06-07 14:16:06 +0930
committerAlan Modra <amodra@gmail.com>2023-06-07 14:16:06 +0930
commitba75d1c55cb42114e3bb5c8abe37e5c2bd657a02 (patch)
tree7e5342433baeaf8305f7a9b08ab58cfc521b4dd4 /bfd/coffgen.c
parent0a22a8f27df7d092620dfa1f0135a2dd7b44528a (diff)
downloadgdb-ba75d1c55cb42114e3bb5c8abe37e5c2bd657a02.zip
gdb-ba75d1c55cb42114e3bb5c8abe37e5c2bd657a02.tar.gz
gdb-ba75d1c55cb42114e3bb5c8abe37e5c2bd657a02.tar.bz2
_bfd_free_cached_info
doc/bfdint.texi and comments in the aout and som code about this function are just wrong, and its name is not very apt. Better would be _bfd_mostly_destroy, and we certainly should not be saying anything about the possibility of later recreating anything lost by this function. What's more, if _bfd_free_cached_info is called when creating an archive map to reduce memory usage by throwing away symbols, the target _close_and_cleanup function won't have access to tdata or section bfd_user_data to tidy memory. This means most of the target _close_and_cleanup function won't do anything, and therefore sometimes will result in memory leaks. This patch fixes the documentation problems and moves most of the target _close_and_cleanup code to target _bfd_free_cached_info. Another notable change is that bfd_generic_bfd_free_cached_info is now defined as _bfd_free_cached_info rather than _bfd_bool_bfd_true, ie. the default now frees objalloc memory.
Diffstat (limited to 'bfd/coffgen.c')
-rw-r--r--bfd/coffgen.c44
1 files changed, 19 insertions, 25 deletions
diff --git a/bfd/coffgen.c b/bfd/coffgen.c
index afc663c..9d45253 100644
--- a/bfd/coffgen.c
+++ b/bfd/coffgen.c
@@ -3275,43 +3275,37 @@ bfd_coff_group_name (bfd *abfd, const asection *sec)
}
bool
-_bfd_coff_close_and_cleanup (bfd *abfd)
+_bfd_coff_free_cached_info (bfd *abfd)
{
- struct coff_tdata *tdata = coff_data (abfd);
+ struct coff_tdata *tdata;
- if (tdata != NULL)
+ if (bfd_family_coff (abfd)
+ && (bfd_get_format (abfd) == bfd_object
+ || bfd_get_format (abfd) == bfd_core)
+ && (tdata = coff_data (abfd)) != NULL)
{
- if (bfd_family_coff (abfd) && bfd_get_format (abfd) == bfd_object)
+ if (tdata->section_by_index)
{
- if (tdata->section_by_index)
- {
- htab_delete (tdata->section_by_index);
- tdata->section_by_index = NULL;
- }
+ htab_delete (tdata->section_by_index);
+ tdata->section_by_index = NULL;
+ }
- if (tdata->section_by_target_index)
- {
- htab_delete (tdata->section_by_target_index);
- tdata->section_by_target_index = NULL;
- }
+ if (tdata->section_by_target_index)
+ {
+ htab_delete (tdata->section_by_target_index);
+ tdata->section_by_target_index = NULL;
}
+ _bfd_dwarf2_cleanup_debug_info (abfd, &tdata->dwarf2_find_line_info);
+ _bfd_stab_cleanup (abfd, &tdata->line_info);
+
/* PR 25447:
Do not clear the keep_syms and keep_strings flags.
These may have been set by pe_ILF_build_a_bfd() indicating
that the syms and strings pointers are not to be freed. */
- if (bfd_get_format (abfd) == bfd_object
- && bfd_family_coff (abfd)
- && !_bfd_coff_free_symbols (abfd))
+ if (!_bfd_coff_free_symbols (abfd))
return false;
-
- if (bfd_get_format (abfd) == bfd_object
- || bfd_get_format (abfd) == bfd_core)
- {
- _bfd_dwarf2_cleanup_debug_info (abfd, &tdata->dwarf2_find_line_info);
- _bfd_stab_cleanup (abfd, &tdata->line_info);
- }
}
- return _bfd_generic_close_and_cleanup (abfd);
+ return _bfd_generic_bfd_free_cached_info (abfd);
}