aboutsummaryrefslogtreecommitdiff
path: root/binutils/dwarf.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2020-12-03 16:10:37 +1030
committerAlan Modra <amodra@gmail.com>2020-12-04 11:12:21 +1030
commit288f0ba26478ec3a8926d54319b9c899e64e26a7 (patch)
tree85c201688e41ebb65db77e9f3d579c90601f507b /binutils/dwarf.c
parent726d7d1ecfd1fc0966983e1d5e59b527b90cf7c5 (diff)
downloadgdb-288f0ba26478ec3a8926d54319b9c899e64e26a7.zip
gdb-288f0ba26478ec3a8926d54319b9c899e64e26a7.tar.gz
gdb-288f0ba26478ec3a8926d54319b9c899e64e26a7.tar.bz2
asan: readelf: memory leaks
This tidies some code used by readelf, hopefully fixing some intermittent oss-fuzz bug reports that likely could only be reproduced by feeding readelf two or more object files on the command line. The second and subsequent file may see non-zero state in .bss variables, and non-initial values in .data variables. This patch fixes some of those, and moves some .data variables to .rodata. * dwarf.c (frame_display_row): Do without static variable "sloc". (cu_tu_indexes_read): Move to file scope. (free_debug_memory): Reset it here, along with level_type_signed. Free and clear a number of other static variables. * readelf.c (arm_attr_public_tag <table>): Constify, updating.. (arm_attr_tag_*): ..all these uses. (process_mips_specific): Free "rels" on error path.
Diffstat (limited to 'binutils/dwarf.c')
-rw-r--r--binutils/dwarf.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index 149755d..96b7a57 100644
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -8187,11 +8187,9 @@ frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_reg
if (*need_col_headers)
{
- static const char *sloc = " LOC";
-
*need_col_headers = 0;
- printf ("%-*s CFA ", eh_addr_size * 2, sloc);
+ printf ("%-*s CFA ", eh_addr_size * 2, " LOC");
for (r = 0; r < *max_regs; r++)
if (fc->col_type[r] != DW_CFA_unreferenced)
@@ -10467,6 +10465,8 @@ process_cu_tu_index (struct dwarf_section *section, int do_display)
return 1;
}
+static int cu_tu_indexes_read = -1; /* Tri-state variable. */
+
/* Load the CU and TU indexes if present. This will build a list of
section sets that we can use to associate a .debug_info.dwo section
with its associated .debug_abbrev.dwo section in a .dwp file. */
@@ -10474,8 +10474,6 @@ process_cu_tu_index (struct dwarf_section *section, int do_display)
static bfd_boolean
load_cu_tu_indexes (void *file)
{
- static int cu_tu_indexes_read = -1; /* Tri-state variable. */
-
/* If we have already loaded (or tried to load) the CU and TU indexes
then do not bother to repeat the task. */
if (cu_tu_indexes_read == -1)
@@ -11249,6 +11247,20 @@ free_debug_memory (void)
cu_abbrev_map = NULL;
next_free_abbrev_map_entry = 0;
+ free (shndx_pool);
+ shndx_pool = NULL;
+ shndx_pool_size = 0;
+ shndx_pool_used = 0;
+ free (cu_sets);
+ cu_sets = NULL;
+ cu_count = 0;
+ free (tu_sets);
+ tu_sets = NULL;
+ tu_count = 0;
+
+ memset (level_type_signed, 0, sizeof level_type_signed);
+ cu_tu_indexes_read = -1;
+
for (i = 0; i < max; i++)
free_debug_section ((enum dwarf_section_display_enum) i);