asan: leak in bfd_section_from_shdr
authorAlan Modra <amodra@gmail.com>
Mon, 2 Nov 2020 23:53:03 +0000 (10:23 +1030)
committerAlan Modra <amodra@gmail.com>
Tue, 3 Nov 2020 00:04:51 +0000 (10:34 +1030)
* elf.c (bfd_section_from_shdr): Free sections_being_created.
Use bfd_zmalloc.

bfd/ChangeLog
bfd/elf.c

index e632282a71cf14ba0d87a0890f2286323b7d3420..94c8e3b3b589ef858766e274d02b9b4c18157964 100644 (file)
@@ -1,3 +1,8 @@
+2020-11-03  Alan Modra  <amodra@gmail.com>
+
+       * elf.c (bfd_section_from_shdr): Free sections_being_created.
+       Use bfd_zmalloc.
+
 2020-11-02  Alan Modra  <amodra@gmail.com>
 
        PR 15146
index 549f661b9d83d3bc36b27e0ede98f58192f9b259..3163d34e8d5024f161adf25582d2bdd0643832dd 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -2061,17 +2061,19 @@ bfd_section_from_shdr (bfd *abfd, unsigned int shindex)
         rather than being held in a static pointer.  */
 
       if (sections_being_created_abfd != abfd)
-       sections_being_created = NULL;
+       {
+         free (sections_being_created);
+         sections_being_created = NULL;
+       }
       if (sections_being_created == NULL)
        {
          size_t amt = elf_numsections (abfd) * sizeof (bfd_boolean);
 
          /* PR 26005: Do not use bfd_zalloc here as the memory might
             be released before the bfd has been fully scanned.  */
-         sections_being_created = (bfd_boolean *) bfd_malloc (amt);
+         sections_being_created = (bfd_boolean *) bfd_zmalloc (amt);
          if (sections_being_created == NULL)
            return FALSE;
-         memset (sections_being_created, FALSE, amt);
          sections_being_created_abfd = abfd;
        }
       if (sections_being_created [shindex])