+ const char *filename = bfd_get_filename (abfd);
+ if (filename)
+ {
+ /* We can't afford to lose the bfd filename when freeing
+ abfd->memory, because that would kill the cache.c scheme
+ of closing and reopening files in order to limit the
+ number of open files. To reopen, you need the filename.
+ And indeed _bfd_compute_and_write_armap calls
+ _bfd_free_cached_info to free up space used by symbols
+ and by check_format_matches. Which we want to continue
+ doing to handle very large archives. Later the archive
+ elements are copied, which might require reopening files.
+ We also want to keep using objalloc memory for the
+ filename since that allows the name to be updated
+ without either leaking memory or implementing some sort
+ of reference counted string for copies of the filename. */
+ size_t len = strlen (filename) + 1;
+ char *copy = bfd_malloc (len);
+ if (copy == NULL)
+ return FALSE;
+ memcpy (copy, filename, len);
+ abfd->filename = copy;
+ }