aboutsummaryrefslogtreecommitdiff
path: root/bfd/bfd.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2019-08-28 16:34:34 +0930
committerAlan Modra <amodra@gmail.com>2019-08-29 07:50:40 +0930
commit83cf0d04dcdc9a4e7f105a517390e4c1af444340 (patch)
tree2dbbfe642b2a4a93041cd660ffe00e3703781d55 /bfd/bfd.c
parent48352473b1d2c213749a324f392cf8ec53d273a6 (diff)
downloadbinutils-83cf0d04dcdc9a4e7f105a517390e4c1af444340.zip
binutils-83cf0d04dcdc9a4e7f105a517390e4c1af444340.tar.gz
binutils-83cf0d04dcdc9a4e7f105a517390e4c1af444340.tar.bz2
PR24891, objdump memory leaks when parsing malformed archive
BFD was leaking memory in bfd_check_format_matches. As part of deciding the proper format of an archive, BFD looks at the format of the first file stored. That file's bfd was left open for reasons given in a comment removed in git commit 0e71e4955cd1 that said: /* We ought to close `first' here, but we can't, because we have no way to remove it from the archive cache. It's close to impossible to figure out when we can release bfd_ardata. FIXME. */ Well, things have changed since that comment was true and we now can remove files from the archive cache. Closing the first file is good and cures some of the leaks. Other leaks are caused by bfd_check_format_matches throwing away bfd tdata before trying a new match. That lost the element cache set up when format checking the first element in the archive. The easiest and cleanest fix is to simply disable the caching when checking the first element. PR 24891 * bfd.c (struct bfd): Add no_element_cache. * archive.c (_bfd_get_elt_at_filepos): Don't add element to archive cache when no_element_cache. (bfd_generic_archive_p): Set no_element_cache when opening first element to check format. Close first element too. (do_slurp_bsd_armap): Don't zero ardata->cache here. * bfd-in2.h: Regenerate.
Diffstat (limited to 'bfd/bfd.c')
-rw-r--r--bfd/bfd.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/bfd/bfd.c b/bfd/bfd.c
index a9b224b..f56a8d3 100644
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -220,6 +220,9 @@ CODE_FRAGMENT
. {* Set if this is a thin archive. *}
. unsigned int is_thin_archive : 1;
.
+. {* Set if this archive should not cache element positions. *}
+. unsigned int no_element_cache : 1;
+.
. {* Set if only required symbols should be added in the link hash table for
. this object. Used by VMS linkers. *}
. unsigned int selective_search : 1;