]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
asan: readelf leaks
authorAlan Modra <amodra@gmail.com>
Thu, 12 Mar 2020 06:18:07 +0000 (16:48 +1030)
committerAlan Modra <amodra@gmail.com>
Thu, 12 Mar 2020 06:30:40 +0000 (17:00 +1030)
* readelf.c (process_section_headers): Don't just set
filedata->section_headers NULL, free it first.  Similarly for
dynamic_symbols, dynamic_strings, dynamic_syminfo and
symtab_shndx_list.  Zero associated counts too.
(process_object): Free symtab_shndx_list.
(process_file): Free various allocated filedata tables.

binutils/ChangeLog
binutils/readelf.c

index 9f54fa1f1c383c01abd164b3ea17eb3b45d8faa3..51a21bf9e9f16e49034390bcbe74452b7f913bb9 100644 (file)
@@ -1,3 +1,12 @@
+2020-03-12  Alan Modra  <amodra@gmail.com>
+
+       * readelf.c (process_section_headers): Don't just set
+       filedata->section_headers NULL, free it first.  Similarly for
+       dynamic_symbols, dynamic_strings, dynamic_syminfo and
+       symtab_shndx_list.  Zero associated counts too.
+       (process_object): Free symtab_shndx_list.
+       (process_file): Free various allocated filedata tables.
+
 2020-03-11  Nick Clifton  <nickc@redhat.com>
 
        PR 25611
index 260ea33ba4c956b0e78c6516da588773c764d7f1..d009b91920bd9304ea72c9aec033afe37a888432 100644 (file)
@@ -6117,6 +6117,7 @@ process_section_headers (Filedata * filedata)
   Elf_Internal_Shdr * section;
   unsigned int i;
 
+  free (filedata->section_headers);
   filedata->section_headers = NULL;
 
   if (filedata->file_header.e_shnum == 0)
@@ -6172,10 +6173,20 @@ process_section_headers (Filedata * filedata)
 
   /* Scan the sections for the dynamic symbol table
      and dynamic string table and debug sections.  */
+  free (dynamic_symbols);
   dynamic_symbols = NULL;
+  num_dynamic_syms = 0;
+  free (dynamic_strings);
   dynamic_strings = NULL;
+  dynamic_strings_length = 0;
+  free (dynamic_syminfo);
   dynamic_syminfo = NULL;
-  symtab_shndx_list = NULL;
+  while (symtab_shndx_list != NULL)
+    {
+      elf_section_list *next = symtab_shndx_list->next;
+      free (symtab_shndx_list);
+      symtab_shndx_list = next;
+    }
 
   eh_addr_size = is_32bit_elf ? 4 : 8;
   switch (filedata->file_header.e_machine)
@@ -20121,6 +20132,13 @@ process_object (Filedata * filedata)
       dynamic_section = NULL;
     }
 
+  while (symtab_shndx_list != NULL)
+    {
+      elf_section_list *next = symtab_shndx_list->next;
+      free (symtab_shndx_list);
+      symtab_shndx_list = next;
+    }
+
   if (section_headers_groups)
     {
       free (section_headers_groups);
@@ -20486,6 +20504,10 @@ process_file (char * file_name)
     }
 
   fclose (filedata->handle);
+  free (filedata->section_headers);
+  free (filedata->program_headers);
+  free (filedata->string_table);
+  free (filedata->dump_sects);
   free (filedata);
 
   return ret;