aboutsummaryrefslogtreecommitdiff
path: root/binutils/readelf.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2020-01-13 22:30:46 +1030
committerAlan Modra <amodra@gmail.com>2020-01-13 22:45:36 +1030
commita788aedd86da983faf0afef3cb41461118a2e9f2 (patch)
tree013d34de70329b9930b0b8f46f1418b32803c7a3 /binutils/readelf.c
parent805f38bc551de820bcd7b31d3c5731ae27cf853a (diff)
downloadgdb-a788aedd86da983faf0afef3cb41461118a2e9f2.zip
gdb-a788aedd86da983faf0afef3cb41461118a2e9f2.tar.gz
gdb-a788aedd86da983faf0afef3cb41461118a2e9f2.tar.bz2
PR23560, PR23561, readelf memory leaks
PR 23560 PR 23561 * dwarf.c (display_debug_frames): Move fde_fc earlier. Free fde_fc col_type and col_offset. * readelf.c (apply_relocations): Move symsec check earlier. (free_debug_section): Free reloc_info. (process_notes_at): Free pnotes on error path. (process_object): Free dump_sects here.. (process_archive): ..not here.
Diffstat (limited to 'binutils/readelf.c')
-rw-r--r--binutils/readelf.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 4326cd0..6b5bebe 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -13333,6 +13333,11 @@ apply_relocations (Filedata * filedata,
|| relsec->sh_link >= filedata->file_header.e_shnum)
continue;
+ symsec = filedata->section_headers + relsec->sh_link;
+ if (symsec->sh_type != SHT_SYMTAB
+ && symsec->sh_type != SHT_DYNSYM)
+ return FALSE;
+
is_rela = relsec->sh_type == SHT_RELA;
if (is_rela)
@@ -13352,10 +13357,6 @@ apply_relocations (Filedata * filedata,
if (filedata->file_header.e_machine == EM_SH)
is_rela = FALSE;
- symsec = filedata->section_headers + relsec->sh_link;
- if (symsec->sh_type != SHT_SYMTAB
- && symsec->sh_type != SHT_DYNSYM)
- return FALSE;
symtab = GET_ELF_SYMBOLS (filedata, symsec, & num_syms);
for (rp = relocs; rp < relocs + num_relocs; ++rp)
@@ -14395,6 +14396,13 @@ free_debug_section (enum dwarf_section_display_enum debug)
section->start = NULL;
section->address = 0;
section->size = 0;
+
+ if (section->reloc_info != NULL)
+ {
+ free (section->reloc_info);
+ section->reloc_info = NULL;
+ section->num_relocs = 0;
+ }
}
static bfd_boolean
@@ -19341,6 +19349,7 @@ process_notes_at (Filedata * filedata,
{
warn (_("Corrupt note: alignment %ld, expecting 4 or 8\n"),
(long) align);
+ free (pnotes);
return FALSE;
}
@@ -20011,6 +20020,13 @@ process_object (Filedata * filedata)
filedata->string_table = NULL;
filedata->string_table_length = 0;
+ if (filedata->dump_sects != NULL)
+ {
+ free (filedata->dump_sects);
+ filedata->dump_sects = NULL;
+ filedata->num_dump_sects = 0;
+ }
+
if (dynamic_strings)
{
free (dynamic_strings);
@@ -20316,13 +20332,6 @@ process_archive (Filedata * filedata, bfd_boolean is_thin_archive)
ret = FALSE;
}
- if (filedata->dump_sects != NULL)
- {
- free (filedata->dump_sects);
- filedata->dump_sects = NULL;
- filedata->num_dump_sects = 0;
- }
-
free (qualified_name);
}