aboutsummaryrefslogtreecommitdiff
path: root/bfd/aoutx.h
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/aoutx.h
parent0a22a8f27df7d092620dfa1f0135a2dd7b44528a (diff)
downloadbinutils-ba75d1c55cb42114e3bb5c8abe37e5c2bd657a02.zip
binutils-ba75d1c55cb42114e3bb5c8abe37e5c2bd657a02.tar.gz
binutils-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/aoutx.h')
-rw-r--r--bfd/aoutx.h36
1 files changed, 17 insertions, 19 deletions
diff --git a/bfd/aoutx.h b/bfd/aoutx.h
index 6d65276..1a8fd85 100644
--- a/bfd/aoutx.h
+++ b/bfd/aoutx.h
@@ -2896,35 +2896,33 @@ NAME (aout, sizeof_headers) (bfd *abfd,
return adata (abfd).exec_bytes_size;
}
-/* Free all information we have cached for this BFD. We can always
- read it again later if we need it. */
+/* Throw away most malloc'd and alloc'd information for this BFD. */
bool
NAME (aout, bfd_free_cached_info) (bfd *abfd)
{
- asection *o;
-
- if (bfd_get_format (abfd) != bfd_object
- || abfd->tdata.aout_data == NULL)
- return true;
-
+ if ((bfd_get_format (abfd) == bfd_object
+ || bfd_get_format (abfd) == bfd_core)
+ && abfd->tdata.aout_data != NULL)
+ {
#define BFCI_FREE(x) do { free (x); x = NULL; } while (0)
- BFCI_FREE (adata (abfd).line_buf);
- BFCI_FREE (obj_aout_symbols (abfd));
+ BFCI_FREE (adata (abfd).line_buf);
+ BFCI_FREE (obj_aout_symbols (abfd));
#ifdef USE_MMAP
- obj_aout_external_syms (abfd) = 0;
- bfd_free_window (&obj_aout_sym_window (abfd));
- bfd_free_window (&obj_aout_string_window (abfd));
- obj_aout_external_strings (abfd) = 0;
+ obj_aout_external_syms (abfd) = 0;
+ bfd_free_window (&obj_aout_sym_window (abfd));
+ bfd_free_window (&obj_aout_string_window (abfd));
+ obj_aout_external_strings (abfd) = 0;
#else
- BFCI_FREE (obj_aout_external_syms (abfd));
- BFCI_FREE (obj_aout_external_strings (abfd));
+ BFCI_FREE (obj_aout_external_syms (abfd));
+ BFCI_FREE (obj_aout_external_strings (abfd));
#endif
- for (o = abfd->sections; o != NULL; o = o->next)
- BFCI_FREE (o->relocation);
+ for (asection *o = abfd->sections; o != NULL; o = o->next)
+ BFCI_FREE (o->relocation);
#undef BFCI_FREE
+ }
- return true;
+ return _bfd_generic_bfd_free_cached_info (abfd);
}
/* a.out link code. */